当前位置:网站首页>【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();
}
}
边栏推荐
- What is the reason why the words behind word disappear when typing? How to solve it?
- P1797 heavy transportation problem solution
- R语言使用dpois函数生成泊松分布密度数据、使用plot函数可视化泊松分布密度数据(Poisson distribution)
- Jmeter安装教程及登录增加token
- Verification code brute force cracking test [easy to understand]
- DXF读写:对齐尺寸标注文字居中、上方的位置计算
- Do you really know esmodule
- LeetCode 105.从前序与中序遍历序列构造二叉树 && 106.从中序与后序遍历序列构造二叉树
- Machine learning (Zhou Zhihua) Chapter 6 notes on Support Vector Learning
- 作为一个程序员,如何高效的管理时间?
猜你喜欢

strcmp、strstr、memcpy、memmove的实现

【服务器数据恢复】HP StorageWorks系列服务器RAID5两块盘离线的数据恢复

Product Manager: job responsibility table

深度学习基础----GNN谱域和空域 (不断完善更新积累)

对“Image Denoising Using an Improved Generative Adversarial Network with Wasserstein Distance“的理解

Machine learning (Zhou Zhihua) Chapter 6 notes on Support Vector Learning

安全保障基于软件全生命周期-PSP应用

什么是自旋锁 自旋锁是指当一个线程尝试获取某个锁时,如果该锁已被其他线程占用,就一直循环检测锁是否被释放,而不是进入线程挂起或睡眠状态。 /** * 为什么用自旋锁:多个线程对同一个变量

安全保障基于软件全生命周期-Istio的授权机制

Algorithm --- different paths (kotlin)
随机推荐
regular expression
掌握闭包,夯实基本功
URL related knowledge points
Jmeter安装教程及登录增加token
Implementation of StrCmp, strstr, memcpy, memmove
30 day question brushing plan (IV)
30天刷题计划(三)
Security assurance is based on software life cycle - networkpolicy application
Several efficient APIs commonly used in inventory operation URL
R语言可视化散点图、使用ggrepel包的geom_text_repel函数避免数据点之间的标签互相重叠(使用参数xlim和ylim将标签添加到可视化图像的特定区域、指定标签线段并添加箭头)
Istio四之故障注入和链路追踪
Verification code brute force cracking test [easy to understand]
SQL daily practice (Niuke new question bank) - day 4: advanced operators
LeetCode 105.从前序与中序遍历序列构造二叉树 && 106.从中序与后序遍历序列构造二叉树
No swagger, what do I use?
Tutorial on the principle and application of database system (058) -- MySQL exercise (2): single choice question
Postgresql14 installation and master-slave configuration
7.依赖注入
Slam thesis collection
Poj1860 currency exchange solution