2
我试图根据Kryo
serlization如何工作。我有一个非常大的HashMap,我想推入Redis
。 HashMap是:使用Kryo将HashMap序列化到Redis
HashMap<String, HashMap<String, Set<Long>>> cache = new HashMap<>();
什么是序列化成Redis
的最快方法?
选项1:直接进入Redis?
我看到,你可以使用Kryo
像:
Kryo kryo = new Kryo();
kryo.register(HashMap.class);
Output output = //For Redis what would the output be ?
kryo. writeObject(output, cache)
但我很困惑,使用Redis
当什么Output
应。
选项2:通过字节数组?
我也看到了,下面也许可能:
Jedis jedis = new Jedis("localhost");
Kryo kryo = new Kryo();
kryo.register(HashMap.class);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Output output = new Output(stream);
kryo.writeObject(output, cache);
output.close();
byte[] buffer = stream.toByteArray();
jedis.set("Test", buffer);
但这似乎效率不高我,我有效地“克隆”我的大缓存为字节数组。
这个问题有效的方法是什么?