我是 Redis 新手,有一个使用 Redisson 将数据放入 Redis 并使用 Jedis 的场景(反之亦然)。我试图维护的数据是 Map
为此,我使用 Jedis 的 HGET API 和 Redisson 的 RMap/RLocalCachedMap 对象。
Logic to Put:
public static String putData(String hash, String key, String value) throws Exception {
RMap<String, String> map = client.getMap(hash);
String previousValue = null;
previousValue = map.put(key, value);
return previousValue;
}
Logic to Get:
public static String getFromHash(String hash, String key) {
Jedis jedis = jedisPool.getResource();
String value = jedis.hget(hash,key);
jedis.close();
return value;
}
我看到的是在持久化数据(使用Redisson)之后,我们能够在Redisson客户端中检索,但是当我们尝试在Jedis中检索这个对象时,我们得到
null
。
问题:
Jedis 对字符串使用 UTF-8 字符集。
您可以在Redisson中尝试类似的编解码器;例如
Utf8StringCodec
。
private static final StringCodec UTF8_CODEC = new StringCodec(StandardCharsets.UTF_8);
// other earlier code
RMap<String, String> map = client.getMap(hash, UTF8_CODEC);
// other later code