当前位置:网站首页>【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();
}
}
边栏推荐
猜你喜欢

Socket class understanding and learning about TCP character stream programming

DXF读写:对齐尺寸标注文字居中、上方的位置计算

SLAM论文合集

30天刷题计划(四)

30 day question brushing plan (III)

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

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

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

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

MySQL开发技巧——视图
随机推荐
掌握闭包,夯实基本功
Dojnoip201708 cheese solution
R语言可视化散点图、使用ggrepel包的geom_text_repel函数避免数据点之间的标签互相重叠(使用参数xlim和ylim将标签添加到可视化图像的特定区域、指定标签线段并添加箭头)
How to play a data mining game entry Edition
[basic course of flight control development 7] crazy shell · open source formation UAV SPI (barometer data acquisition)
Thoroughly master binary search
安全保障基于软件全生命周期-Istio的授权机制
Understand the principle behind the virtual list, and easily realize the virtual list
R语言使用dpois函数生成泊松分布密度数据、使用plot函数可视化泊松分布密度数据(Poisson distribution)
TS literacy method - Basic chapter
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
Poj3259 wormhole solution
On websocket
R language ggplot2 visualization: visualize the scatter diagram and add text labels to the data points in the scatter diagram, using geom of ggrep package_ text_ The rep function avoids overlapping da
关于栈的理解以及实际应用场景
SLAM论文合集
了解BFC特性,轻松实现自适应布局
redis哨兵机制
Socket类关于TCP字符流编程的理解学习
Clickhouse架构与设计