当前位置:网站首页>[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();
}
}
边栏推荐
- 30 day question brushing training (I)
- R language uses dpois function to generate Poisson distribution density data and plot function to visualize Poisson distribution density data
- Vite configuring path aliases in the project
- Several efficient APIs commonly used in inventory operation URL
- 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
- a标签_文件下载(download属性)
- regular expression
- [lvgl events] Application of events on different components (I)
- Verification code brute force cracking test [easy to understand]
- R语言检验样本比例:使用prop.test函数执行单样本比例检验计算总体中成功样本比例p值的置信区间(设置conf.level参数指定置信水平、置信区间的大小)
猜你喜欢
随机推荐
第六章 支持向量机
Several efficient APIs commonly used in inventory operation URL
leetcode-深度优先与广度优先遍历
基于NoneBot2的qq机器人配置记录
Discrete logarithm problem (DLP) & Diffie Hellman problem (DHP)
RSA用私钥加密数据公钥解密数据(不是签名验证过程)
TS扫盲大法-基础篇
Master several common sorting - Select Sorting
30 day question brushing plan (II)
【Util】redis工具类:把redis的value序列化器修改为GenericJackson2JsonRedisSerializer,就支持返回值为对象或集合了
【Utils】FastDFS工具类
DXF读写:标注样式组码中文说明
Long closed period private placement products reappearance industry insiders have different views
Jmeter安装教程及登录增加token
每日一题——奖学金
R language Visual scatter diagram, geom using ggrep package_ text_ The repl function avoids overlapping labels between data points (add labels to specific areas of the visual image using the parameter
Several solutions to spanning
安全保障基于软件全生命周期-PSP应用
DXF读写:对齐尺寸标注文字居中、上方的位置计算
DXF reading and writing: Chinese description of dimension style group codes








