private boolean enableDefaultSerializer = true; private RedisSerializer<?> defaultSerializer = new JdkSerializationRedisSerializer(); private RedisSerializer keySerializer = null; private RedisSerializer valueSerializer = null; private RedisSerializer hashKeySerializer = null; private RedisSerializer hashValueSerializer = null;
解決方法redis
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的數據,都須要序列化,若是用redis默認的序列化類,會致使存到redis數據庫的數據可讀性不太好,就是上面第一圖,實際讀取出來的數據與存進去的是同樣的,只是直接訪問redis會發現好像亂碼的樣子,可讀性很差。那麼,實際上是能夠使用其餘類序列化redis的key和value的。spring