http://xiangai.taobao.com
http://shop148612228.taobao.com

springboot redis key乱码

原写法:

@Autowired
private RedisTemplate redisTemplate;

 

写入redis后,查看key值

复制代码
127.0.0.1:6379> keys *
1) "\xac\xed\x00\x05t\x00#ContentPlatform2:ES:UpSertESContent"
2) "\xac\xed\x00\x05t\x00%ContentPlatform2:Lock_v16:CJH_ARTICLE"
3) "\xac\xed\x00\x05t\x00!ContentPlatform2:Lock_v16:V_VIDEO"
4) "\xac\xed\x00\x05t\x00\x1bContentPlatform2:ES:Content"
5) "\xac\xed\x00\x05t\x00#ContentPlatform2:Lock_v16:CJH_VIDEO"
6) "\xac\xed\x00\x05t\x00%ContentPlatform2:Lock_v16:CMS_ARTICLE"
复制代码

 

解决方式:

复制代码
private RedisTemplate redisTemplate;

@Autowired(required = false)
public void setRedisTemplate(RedisTemplate redisTemplate) {
     RedisSerializer stringSerializer = new StringRedisSerializer();
     redisTemplate.setKeySerializer(stringSerializer);
     redisTemplate.setValueSerializer(stringSerializer);
     redisTemplate.setHashKeySerializer(stringSerializer);
     redisTemplate.setHashValueSerializer(stringSerializer);
     this.redisTemplate = redisTemplate;
}
复制代码

 

调整后查看redis key值:

127.0.0.1:6379> keys *
1) "ContentPlatform2:Lock_v17:V_VIDEO"
2) "ContentPlatform2:Lock_v17:CMS_ARTICLE"
3) "ContentPlatform2:ES:Content"
4) "ContentPlatform2:Lock_v17:CJH_ARTICLE”

 

作者:陈敬(Cathy) 
出处:http://www.cnblogs.com/janes/ 
博客文章仅供交流学习,请勿用于商业用途。如需转载,请务必注明出处。

posted @ 2019-08-27 16:02  万事俱备就差个程序员  阅读(2748)  评论(0编辑  收藏  举报

http://xiangai.taobao.com
http://shop148612228.taobao.com
如果您觉得对您有帮助.领个红包吧.谢谢.
支付宝红包
微信打赏 支付宝打赏