redis常见字符乱码问题及解决办法

2022-12-27 16:09:50 浏览数 (1)

问题

redis保存数据后出现xacxedx00x05tx00

解决办法

创建一个配置类

代码语言:javascript复制
@Configuration
public class RedisTemplateBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if(RedisTemplate.class.isAssignableFrom(bean.getClass())) {
            RedisTemplate redisTemplate = (RedisTemplate)bean;
            StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
            redisTemplate.setKeySerializer(stringRedisSerializer);
            redisTemplate.setValueSerializer(stringRedisSerializer);
        }
        return bean;
    }
}

然后重启项目,再去试试,看看是不是ok了

0 人点赞