Redis Desktop Manager 显示二进制乱码问题
在SpringBoot项目中前面还多出了许多类似\xac\xed\x00\x05t\x00这种字符串,如下图第二个key解决办法非常简单 添加一个RedisConfig类代码如下package demo.shiro.config;import org.springframework.context.annotation.Bean;import org.springframework.context
·
在SpringBoot项目中
前面还多出了许多类似\xac\xed\x00\x05t\x00这种字符串,如下图第二个key
解决办法非常简单 添加一个RedisConfig类
代码如下
package demo.shiro.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
@Configuration
public class RedisConfig {
@Bean(name="redisTemplate")
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
System.out.println("\n Redis开启序列化");
RedisTemplate<String, String> 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;
}
}
SpringBoot在启动的时候也会提前加载这个类
最后我们所看到的数据就正常啦
更多推荐
已为社区贡献3条内容
所有评论(0)