当前位置:网站首页>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
边栏推荐
- 解决报错:ImportError: IProgress not found. Please update jupyter and ipywidgets
- 自定义异常类
- 字符串(String)笔记
- Opensips (1) -- detailed process of installing opensips
- Multithreading and high concurrency (1) -- basic knowledge of threads (implementation, common methods, state)
- Pytorch学习记录(五):反向传播+基于梯度的优化器(SGD,Adagrad,RMSporp,Adam)
- idea插件---背景播放歌曲
- mysql实现主从复制/主从同步
- PyQy5学习(三):QLineEdit+QTextEdit
- jdbc入门\获取数据库连接\使用PreparedStatement
猜你喜欢

PyQy5学习(四):QAbstractButton+QRadioButton+QCheckBox

第36期《AtCoder Beginner Contest 248 打比赛总结》

深入源码分析Servlet第一个程序

Pytoch learning record (x): data preprocessing + batch normalization (BN)

Manually delete registered services on Eureka

Multithreading and high concurrency (3) -- synchronized principle

opensips(1)——安装opensips详细流程

Transposed convolution

关于二叉树的遍历

字符串(String)笔记
随机推荐
Getting started with JDBC \ getting a database connection \ using Preparedstatement
PyQy5学习(三):QLineEdit+QTextEdit
Pytoch learning record (x): data preprocessing + batch normalization (BN)
lambda表达式
Pytorch學習記錄(十三):循環神經網絡((Recurrent Neural Network)
C language - Spoof shutdown applet
Conda 虚拟环境管理(创建、删除、克隆、重命名、导出和导入)
delete和truncate
事实最终变量与最终变量
poi生成excel,插入图片
poi导出excel,行相同数据自动合并单元格
Excel obtains the difference data of two columns of data
尚硅谷 p290 多态性练习
freemark中插入图片
MySQL create Oracle exercise table
MySQL事务
Step on the pit: Nacos uses startup CMD - M standalone startup error
xxl-job采坑指南xxl-rpc remoting error(connect timed out)
关于二叉树的遍历
Strategies to improve Facebook's touch rate and interaction rate | intelligent customer service helps you grasp users' hearts