当前位置:网站首页>【Util】redis工具类:把redis的value序列化器修改为GenericJackson2JsonRedisSerializer,就支持返回值为对象或集合了
【Util】redis工具类:把redis的value序列化器修改为GenericJackson2JsonRedisSerializer,就支持返回值为对象或集合了
2022-07-28 13:12:00 【一鸭一鸭唷】
import org.springframework.cache.CacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.cache.RedisCacheWriter;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import java.time.Duration;
@Configuration
public class RedisConfig {
@Bean
public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {
//缓存配置对象
RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig();
redisCacheConfiguration = redisCacheConfiguration.entryTtl(Duration.ofMinutes(30L)) //设置缓存的默认超时时间:30分钟
.disableCachingNullValues() //如果是空值,不缓存
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer())) //设置key序列化器
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer())); //设置value序列化器
return RedisCacheManager
.builder(RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory))
.cacheDefaults(redisCacheConfiguration).build();
}
}
边栏推荐
- R language ggplot2 visualization: use ggviolin function of ggpubr package to visualize violin diagram and set draw_ The quantiles parameter adds a specified quantile horizontal line (for example, 50%
- How to play a data mining game entry Edition
- Dojnoip201708 cheese solution
- leetcode-深度优先与广度优先遍历
- MySQL开发技巧——视图
- Clickhouse分布式集群搭建
- 盘点操作URL中常用的几个高效API
- [lvgl events] Application of events on different components (I)
- Holes in [apue] files
- R语言使用lm函数构建多元回归模型(Multiple Linear Regression)、并根据模型系数写出回归方程、使用confint函数给出回归系数的95%置信区间
猜你喜欢
随机推荐
安全保障基于软件全生命周期-NetworkPolicy应用
[lvgl events] event code
R语言检验样本比例:使用prop.test函数执行单样本比例检验计算总体中成功样本比例p值的置信区间(设置conf.level参数指定置信水平、置信区间的大小)
[lvgl events] Application of events on different components (I)
ES6 what amazing writing methods have you used
多级缓存方案
Several efficient APIs commonly used in inventory operation URL
Slam thesis collection
Several solutions to spanning
牛客多校-Link with Level Edito I-(线性dp)
了解虚拟列表背后原理,轻松实现虚拟列表
Dojnoip201708 cheese solution
算法---不同路径(Kotlin)
Postgresql14 installation and master-slave configuration
The strongest distributed locking tool: redisson
离散对数问题(DLP) && Diffie-Hellman问题(DHP)
[Architecture] reading notes of three micro service books with high scores
掌握常见的几种排序-选择排序
R language ggplot2 visualization: use the ggviolin function of ggpubr package to visualize violin diagrams, set the palette parameter, and customize the border colors of violin diagrams at different l
Understanding of "image denoising using an improved generic advantageous network with Wasserstein distance"







