SpringBoot整合Redis,解决乱码问题

概述

通常用SpringBoot整合Redis后会出现乱码问题,通常的解决方案是将Redis重新序列化

demo

加上如下配置,就不会出现xx0x3/xx9x,等键值乱码问题了

@Configuration
public class RedisConfig {

    @Autowired
    private RedisConnectionFactory factory;

    @Bean
    public RedisTemplate<String, Object> redisTemplate() {
        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        redisTemplate.setHashKeySerializer(new StringRedisSerializer());
        redisTemplate.setHashValueSerializer(new StringRedisSerializer());
        redisTemplate.setValueSerializer(new StringRedisSerializer());
        redisTemplate.setConnectionFactory(factory);
        return redisTemplate;
    }

}

你可能感兴趣的:(redis,redis,spring,boot,java)