redisTemplate获取redis的set类型和hash类型报错

查明原因是序列化转换的问题,每个类型都有对应的序列化转换set和hash如下:
redisTemplate.setValueSerializer(new StringRedisSerializer());
Set<String> users =redisTemplate.opsForSet().members("xxxxx");


// 获取 Hash 数据
RedisSerializer redisSerializer = new RedisSerializer() {
@Override
public byte[] serialize(Object o) throws SerializationException {
return JSON.toJSONBytes(o);
}

@Override
public Object deserialize(byte[] bytes) throws SerializationException {
String obj = new String(bytes);
return obj;
}
};
redisTemplate.setHashValueSerializer(redisSerializer);
Map<String,String> userMap = redisTemplate.opsForHash().entries("xxxxx");

 

posted @ 2024-11-29 16:46  蓝海的bug本  阅读(3)  评论(0编辑  收藏  举报