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/ 
博客文章僅供交流學習,請勿用於商業用途。如需轉載,請務必注明出處。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM