RedisTemplate操作redis时,key值出现\xac\xed\x00\x05t\x00前缀

现象:

使用redistemplate操作redis,随后在客户端keys * 查询,发现key值多了前缀,但是不影响程序读写

经查阅资料,是RedisTemplate默认序列化方式用的是JdkSerializationRedisSerializer,此时我将key序列化方式改成StringRedisSerializer,将value序列化方式改为Jackson2JsonRedisSerializer

代码如下

    private RedisTemplate redisTemplate;

    @Autowired(required = false)
    public void setRedisTemplate(RedisTemplate redisTemplate) {
        RedisSerializer stringSerializer = new StringRedisSerializer();//序列化为String
        Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);//序列化为Json
        redisTemplate.setKeySerializer(stringSerializer);
        redisTemplate.setValueSerializer(jackson2JsonRedisSerializer);
        redisTemplate.setHashKeySerializer(stringSerializer);
        redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer);
        this.redisTemplate = redisTemplate;
    }

修改后再操作,前缀不见了

最后附上常见的序列化方式

ps:此图转自

https://img-blog.csdn.net/20160822203615371?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center

你可能感兴趣的:(技术学习)