玩转springboot之springboot集成redis乱码问题

springboot集成redis乱码问题

在使用redis操作字符串时发现会变成乱码,这是因为RedisTemplate默认是使用的是JdkSerializationRedisSerializer序列化方式,这里可以使用StringRedisTemplate来进行操作,StringRedisTemplate中默认使用的是StringRedisSerializer

也可以对RedisTemplate进行配置,设置其序列化方式

复制代码
@Configuration
public class RedisConfig {

    // 配置redisTemplate
    @Bean
    public RedisTemplate<String,Object> redisTemplate(RedisConnectionFactory factory){
        RedisTemplate<String,Object> redisTemplate = new RedisTemplate<>();
        redisTemplate.setConnectionFactory(factory);
        // 设置key的序列化
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        // value的序列化
        Jackson2JsonRedisSerializer jsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
        redisTemplate.setValueSerializer(jsonRedisSerializer);

        return redisTemplate;
    }
}

https://zhhll.icu/2022/框架/springboot/集成/1.springboot集成redis乱码问题/
© 著作权归作者所有,转载或内容合作请联系作者

喜欢的朋友记得点赞、收藏、关注哦!!!

相关推荐
Wx-bishekaifayuan11 分钟前
springboot房屋租赁系统11574-计算机课程设计、毕业设计
java·vue.js·spring boot·后端·sql·spring·课程设计
欣欣之王来了11 分钟前
AI合规专项:AI自动化决策的合规管控要点
运维·人工智能·自动化
小白的码BUG之路15 分钟前
Docker -- 构建nginx镜像,启动vue项目
vue.js·nginx·docker
guo_wen_qiang18 分钟前
docker安装常见软件集合
运维·docker·容器
谷哥的小弟22 分钟前
CentOS寿终正寝
linux·运维·centos
醇氧23 分钟前
nohup 后台启动 uvicorn(仅测试 / 临时运行)
linux·运维·网络·python·python3.11
海宇AI26 分钟前
零信任架构实战:基于海宇车辆估值构建自动化二手车收车测算网关
运维·人工智能·架构·自动化
雪落漂泊26 分钟前
Linux基本指令(上)
linux·运维·服务器
三84427 分钟前
Fastjson 漏洞学习笔记 · 03 · 经典利用链:TemplatesImpl 与 JdbcRowSetImpl
java·web安全·fastjson
青山木31 分钟前
秒杀系统设计(二):数据正确性——防超卖、分布式锁与一人一单
分布式·后端·mysql·中间件·架构