I want to store Java data structures in Redis. I wrote code in Java as below:
public static void main(String[] args) throws IOException {
Map<String, String> map = new HashMap<String, String>();
map.put("foo", "1");
map.put("bar", "2");
map.put("baz", "3");
ArrayList<String> list = new ArrayList<String>();
list.add("foo");
list.add("bar");
MessagePack mp = new MessagePack();
byte[] serializedMap = mp.write(map);
byte[] serializedList = mp.write(list);
Jedis jedis = new Jedis("localhost");
jedis.zadd("test".getBytes(), 1000, serializedMap);
jedis.zadd("test2".getBytes(), 1000, serializedList);
jedis.close();
}
I have no problem with deserializing in Redis value (serializedList) of "test2":
eval "local r = redis.call('zrange', 'test2', 0, 1); return cmsgpack.unpack(r[1]);" 0
1) "foo"
2) "bar"
Unfortunately, I can't deal with serializedMap. I tried, with no luck, something like this:
eval "local r = redis.call('zrange', 'test', 0, 1); return cmsgpack.unpack(r[1]);" 0
(empty list or set)
Can anybody give me a hint how to do that correctly?