当前位置:网站首页>[util] redis tool class: change the value serializer of redis to genericjackson2jsonredisserializer, and the return value can be object or collection
[util] redis tool class: change the value serializer of redis to genericjackson2jsonredisserializer, and the return value can be object or collection
2022-07-28 14:10:00 【One duck, one duck】
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) {
// Cache configuration objects
RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig();
redisCacheConfiguration = redisCacheConfiguration.entryTtl(Duration.ofMinutes(30L)) // Set the default timeout for caching :30 minute
.disableCachingNullValues() // If it's null , Don't cache
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer())) // Set up key Serializer
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer())); // Set up value Serializer
return RedisCacheManager
.builder(RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory))
.cacheDefaults(redisCacheConfiguration).build();
}
}
边栏推荐
- Socket class understanding and learning about TCP character stream programming
- 牛客多校-Link with Level Edito I-(线性dp)
- regular expression
- Dojnoip201708 cheese solution
- 基于NoneBot2的qq机器人配置记录
- 协同办公工具:在线白板初起步,在线设计已红海
- 数据库系统概论(第5版)补充习题——第一章 绪论
- Qt5 development from introduction to mastery -- the first overview
- Poj3268 shortest path solution
- 【Utils】JsonUtil
猜你喜欢

Deploy application delivery services in kubernetes (Part 1)

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

LeetCode 0142.环形链表 II

Socket class understanding and learning about TCP character stream programming

Understanding of "image denoising using an improved generic advantageous network with Wasserstein distance"

离散对数问题(DLP) && Diffie-Hellman问题(DHP)

Clickhouse架构与设计

MySQL开发技巧——视图

Jmeter安装教程及登录增加token

作为一个程序员,如何高效的管理时间?
随机推荐
Slam thesis collection
R language uses LM function to build linear regression model and subset function to specify subset of data set to build regression model (use floor function and length function to select the former pa
Long closed period private placement products reappearance industry insiders have different views
了解BFC特性,轻松实现自适应布局
TS扫盲大法-基础篇
Docker deploys Mysql to realize remote connection [easy to understand]
DXF读写:对齐尺寸标注文字居中、上方的位置计算
LeetCode 0143. 重排链表
如何有效进行回顾会议(上)?
深度学习基础----GNN谱域和空域 (不断完善更新积累)
Diablo 4 ps4/ps5 beta has been added to the Playstation database
解决uniapp微信小程序canvas不能引入字体的问题
什么是自旋锁 自旋锁是指当一个线程尝试获取某个锁时,如果该锁已被其他线程占用,就一直循环检测锁是否被释放,而不是进入线程挂起或睡眠状态。 /** * 为什么用自旋锁:多个线程对同一个变量
Vite configuring path aliases in the project
[lvgl events] event code
【Utils】CookieUtil
阿里、京东、抖音:把云推向产业心脏
安全保障基于软件全生命周期-PSP应用
IntersectionObserver交叉观察器
R语言检验样本比例:使用prop.test函数执行单样本比例检验计算总体中成功样本比例p值的置信区间(设置conf.level参数指定置信水平、置信区间的大小)