如图, 用RedisDesktopManager显示的乱码
前提是项目中引入了redis的依赖
1 2 3 4 5
| <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>
|
在运行代码添加如下配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| @Configuration public class RedisConfig { @Autowired private RedisTemplate redisTemplate;
@Bean public RedisTemplate redisTemplateInit() { redisTemplate.setKeySerializer(new StringRedisSerializer()); redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer()); return redisTemplate; } }
|
参考: