当前位置:网站首页>[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();
}
}
边栏推荐
- 【LVGL事件(Events)】事件代码
- Holes in [apue] files
- regular expression
- Long closed period private placement products reappearance industry insiders have different views
- Master several common sorting - Select Sorting
- Socket类关于TCP字符流编程的理解学习
- 掌握常见的几种排序-选择排序
- Jmeter安装教程及登录增加token
- 30 day question brushing plan (III)
- 基于NoneBot2的qq机器人配置记录
猜你喜欢

LeetCode 105.从前序与中序遍历序列构造二叉树 && 106.从中序与后序遍历序列构造二叉树

Istio IV fault injection and link tracking

作为一个程序员,如何高效的管理时间?

Security assurance is based on software life cycle -istio authorization mechanism

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

一文读懂如何部署具有外部数据库的高可用 K3s

7.依赖注入

What is the reason why the words behind word disappear when typing? How to solve it?

Chapter 6 support vector machine
![[lvgl events] Application of events on different components (I)](/img/a8/7c24e68f3506bbef3c2e922729471c.png)
[lvgl events] Application of events on different components (I)
随机推荐
webSocket聊天
Qt5开发从入门到精通——第一篇概述
数据库系统概论(第5版)补充习题——第一章 绪论
Thoroughly master binary search
什么是自旋锁 自旋锁是指当一个线程尝试获取某个锁时,如果该锁已被其他线程占用,就一直循环检测锁是否被释放,而不是进入线程挂起或睡眠状态。 /** * 为什么用自旋锁:多个线程对同一个变量
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%
R语言因子数据的表格和列联表(交叉表)生成:使用summay函数分析列表查看卡方检验结果判断两个因子变量是否独立(使用卡方检验验证独立性)
【Utils】ServletUtil
【服务器数据恢复】HP StorageWorks系列服务器RAID5两块盘离线的数据恢复
在 Kubernetes 中部署应用交付服务(第 1 部分)
关于栈的理解以及实际应用场景
The strongest distributed locking tool: redisson
Multithreading and high concurrency (III) -- source code analysis AQS principle
安全保障基于软件全生命周期-Istio的授权机制
解决跨越的几种方案
strcmp、strstr、memcpy、memmove的实现
Product Manager: job responsibility table
R语言检验样本比例:使用prop.test函数执行单样本比例检验计算总体中成功样本比例p值的置信区间(设置conf.level参数指定置信水平、置信区间的大小)
【Utils】CookieUtil
算法---不同路径(Kotlin)