码迷,mamicode.com
首页 > 其他好文 > 详细

Redis

时间:2020-07-18 15:42:47      阅读:56      评论:0      收藏:0      [点我收藏+]

标签:相关配置   ali   public   ret   setvalue   val   comment   序列   连接   

redis序列化

/** * redis相关配置 */ @Configuration //开启注解缓存 @EnableCaching public class RedisConfig{ /** * redis序列化配置 * @param connectionFactory jedis连接工厂 * @return */ @Bean public RedisTemplate redisTemplate(JedisConnectionFactory connectionFactory) { RedisTemplate redisTemplate = new RedisTemplate(); redisTemplate.setConnectionFactory(connectionFactory); // 使用Jackson2JsonRedisSerialize 替换默认序列化 Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); jackson2JsonRedisSerializer.setObjectMapper(objectMapper); // 设置value的序列化规则和 key的序列化规则 redisTemplate.setValueSerializer(jackson2JsonRedisSerializer); redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer); redisTemplate.setKeySerializer(new StringRedisSerializer()); redisTemplate.setHashKeySerializer(redisTemplate.getKeySerializer()); redisTemplate.afterPropertiesSet(); return redisTemplate; } }

Redis

标签:相关配置   ali   public   ret   setvalue   val   comment   序列   连接   

原文地址:https://www.cnblogs.com/ma919755374/p/13335090.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!