使用Redisson放入数据并使用Jedis获取

问题描述 投票:0回答:1

我是 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

问题:

  1. Redisson RMap 对象不会转换为 Redis 中的 HSET 吗?
  2. 如果是这样,有人可以建议我在这里做错了什么吗?
java redis jedis redisson
1个回答
0
投票

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
© www.soinside.com 2019 - 2024. All rights reserved.