当前位置:网站首页>Write your own redistemplate
Write your own redistemplate
2022-04-23 05:51:00 【Lin Zi 520】
package com.lzjtu.config;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
/** * Created by DELL on 2021/3/17 */
@Configuration
public class RedisConfig {
// Write your own redisTemplate
@Bean
@SuppressWarnings("all")
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
// We develop for our own convenience , It is usually used directly <String, Object>
RedisTemplate<String, Object> template = new RedisTemplate();
template.setConnectionFactory(factory);
// Json Serialization configuration
Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer =
new Jackson2JsonRedisSerializer<Object>(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(om);
// String Serialization
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
// Configure the specific serialization method
// key use String How to serialize
template.setKeySerializer(stringRedisSerializer);
// hash Of key Also used String How to serialize
template.setHashKeySerializer(stringRedisSerializer);
// value Serialization is adopted jackson
template.setValueSerializer(jackson2JsonRedisSerializer);
// hash Of value The serialization method adopts Jackson
template.setHashValueSerializer(jackson2JsonRedisSerializer);
template.afterPropertiesSet();
return template;
}
}
版权声明
本文为[Lin Zi 520]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230543037428.html
边栏推荐
- The list attribute in the entity is empty or null, and is set to an empty array
- refused connection
- Step on the pit: Nacos uses startup CMD - M standalone startup error
- TypeScript interface & type 粗略理解
- xxl-job采坑指南xxl-rpc remoting error(connect timed out)
- POI generates excel and inserts pictures
- 多线程与高并发(3)——synchronized原理
- rsync实现文件服务器备份
- 软件架构设计——软件架构风格
- interviewter:介绍一下MySQL日期函数
猜你喜欢
Dva中在effects中获取state的值
实操—Nacos安装与配置
‘EddiesObservations‘ object has no attribute ‘filled‘
Font shape `OMX/cmex/m/n‘ in size <10.53937> not available (Font) size <10.95> substituted.
C language - Spoof shutdown applet
opensips(1)——安装opensips详细流程
Ora: 28547 connection to server failed probable Oracle net admin error
mysql sql优化之Explain
线程的底部实现原理—静态代理模式
基于thymeleaf实现数据库图片展示到浏览器表格
随机推荐
MDN文档里面入参写法中括号‘[]‘的作用
lambda表达式
Software architecture design - software architecture style
Character recognition easyocr
对象转map
mysql中duplicate key update
Navicate连接oracle(11g)时ORA:28547 Connection to server failed probable Oeacle Net admin error
Pytorch学习记录(五):反向传播+基于梯度的优化器(SGD,Adagrad,RMSporp,Adam)
JS number capitalization method
JVM family (4) -- memory overflow (OOM)
mysql-触发器、存储过程、存储函数
Multithreading and high concurrency (1) -- basic knowledge of threads (implementation, common methods, state)
Pytorch學習記錄(十三):循環神經網絡((Recurrent Neural Network)
Add days to date
ES6之解构函数
MySQL create Oracle exercise table
软件架构设计——软件架构风格
域内用户访问域外samba服务器用户名密码错误
rsync实现文件服务器备份
The role of brackets' [] 'in the parameter writing method in MDN documents