当前位置:网站首页>【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();
}
}
边栏推荐
- P1797 heavy transportation problem solution
- R language uses LM function to build multiple linear regression model, writes regression equation according to model coefficient, and uses conflict function to give 95% confidence interval of regressi
- Several efficient APIs commonly used in inventory operation URL
- Understanding of stack and practical application scenarios
- [Architecture] reading notes of three micro service books with high scores
- 你真的了解esModule吗
- Uva11175 digraph D and E from D to e and back
- word打字时后面的字会消失是什么原因?如何解决?
- Chapter 6 support vector machine
- DXF读写:标注样式组码中文说明
猜你喜欢

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

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

【飞控开发基础教程7】疯壳·开源编队无人机-SPI(气压计数据获取)
![[basic course of flight control development 7] crazy shell · open source formation UAV SPI (barometer data acquisition)](/img/ad/e0bc488c238a260768f7e7faec87d0.png)
[basic course of flight control development 7] crazy shell · open source formation UAV SPI (barometer data acquisition)

修订版 | 目标检测:速度和准确性比较(Faster R-CNN,R-FCN,SSD,FPN,RetinaNet和YOLOv3)...
![[lvgl events] Application of events on different components (I)](/img/a8/7c24e68f3506bbef3c2e922729471c.png)
[lvgl events] Application of events on different components (I)

目标检测:速度和准确性比较(Fater R-CNN,R-FCN,SSD,FPN,RetinaNet和YOLOv3)

7.依赖注入

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

30 day question brushing training (I)
随机推荐
TS literacy method - Basic chapter
R language test sample proportion: use prop The test function performs the single sample proportion test to calculate the confidence interval of the p value of the successful sample proportion in the
安全保障基于软件全生命周期-Istio的认证机制
IP黑白名单
30 day question brushing plan (IV)
Clickhouse分布式集群搭建
安全保障基于软件全生命周期-NetworkPolicy应用
一文读懂如何部署具有外部数据库的高可用 K3s
ES6 what amazing writing methods have you used
Graph traversal (BFS & DFS basis)
111. The sap ui5 fileuploader control realizes local file upload and encounters a cross domain access error when receiving the response from the server
Master several common sorting - Select Sorting
R语言ggplot2可视化:使用ggpubr包的ggviolin函数可视化小提琴图、设置draw_quantiles参数添加指定分位数横线(例如,50%分位数、中位数)
Rust from introduction to mastery 01 introduction
安全保障基于软件全生命周期-Istio的授权机制
关于栈的理解以及实际应用场景
IntersectionObserver交叉观察器
Several efficient APIs commonly used in inventory operation URL
R语言因子数据的表格和列联表(交叉表)生成:使用summay函数分析列表查看卡方检验结果判断两个因子变量是否独立(使用卡方检验验证独立性)
第六章 支持向量机