当前位置:网站首页>【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();
}
}
边栏推荐
- 数据库系统概论(第5版)补充习题——第一章 绪论
- 阿里、京东、抖音:把云推向产业心脏
- 掌握闭包,夯实基本功
- 离散对数问题(DLP) && Diffie-Hellman问题(DHP)
- Poj3268 shortest path solution
- 最强分布式锁工具:Redisson
- Generation of tables and contingency tables (cross tables) of R language factor data: use the summary function to analyze the list, view the chi square test results, and judge whether the two factor v
- SAP ui5 fileuploader control realizes local file upload, and trial version of cross domain access error encountered when receiving server-side response
- DXF reading and writing: Chinese description of dimension style group codes
- 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
猜你喜欢

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

IP黑白名单

产品经理:岗位职责表

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

Istio四之故障注入和链路追踪

Socket class understanding and learning about TCP character stream programming

The strongest distributed locking tool: redisson

第六章 支持向量机

RSA用私钥加密数据公钥解密数据(不是签名验证过程)

Slam thesis collection
随机推荐
安全保障基于软件全生命周期-Istio的认证机制
Postgresql14安装及主从配置
Clickhouse架构与设计
Master closures and consolidate basic skills
Security assurance is based on software life cycle -psp application
DXF reading and writing: align the calculation of the position of the dimension text in the middle and above
7.27模拟赛总结
DXF读写:标注样式组码中文说明
牛客多校-Link with Level Edito I-(线性dp)
A label_ File download (download attribute)
基于NoneBot2的qq机器人配置记录
了解BFC特性,轻松实现自适应布局
【飞控开发基础教程7】疯壳·开源编队无人机-SPI(气压计数据获取)
Poj3275 ranking the cows
30 day question brushing plan (IV)
Poj1860 currency exchange solution
30天刷题计划(二)
彻底掌握二分查找
30天刷题计划(四)
leetcode(442)数组中重复的数据