解决 redis 的 key 出现的序列化 \xac\xed\x00\x05t\x00 乱码问题
解决办法:添加 redis 配置类,配置使用的序列化方式
@Configuration
public class RedisConfig {
@Bean(name = "redisTemplate")
public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory factory) {
RedisTemplate<Object, Object> template = new RedisTemplate<>();
RedisSerializer<String> redisSerializer = new StringRedisSerializer();
template.setConnectionFactory(factory);
//key序列化方式
template.setKeySerializer(redisSerializer);
//value序列化
template.setValueSerializer(redisSerializer);
//value hashmap序列化
template.setHashValueSerializer(redisSerializer);
//key haspmap序列化
template.setHashKeySerializer(redisSerializer);
return template;
}
}
@Autowired private RedisTemplate<String,String> redisTemplate;
原文链接:https://blog.csdn.net/m4330187/article/details/108091447