当前位置:网站首页>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
边栏推荐
- 2-軟件設計原則
- 类的加载与ClassLoader的理解
- mysql-触发器、存储过程、存储函数
- JVM series (3) -- memory allocation and recycling strategy
- io.lettuce.core.RedisCommandExecutionException: ERR wrong number of arguments for ‘auth‘ command
- Contract lock loophole
- mysql如何将存储的秒转换为日期
- Common status codes
- Strategy for improving the conversion rate of independent stations | recovering abandoned users
- K/3 WISE系统考勤客户端日期只能选到2019年问题
猜你喜欢

Pilotage growth · ingenuity empowerment -- yonmaster developer training and pilotage plan is fully launched

Multithreading and high concurrency (2) -- detailed explanation of synchronized usage

Batch import of orange single micro service

C language - Spoof shutdown applet

域内用户访问域外samba服务器用户名密码错误

mysql sql优化之Explain

基于ssm 包包商城系统

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

图解HashCode存在的意义

MySQL的锁机制
随机推荐
JDBC操作事务
refused connection
JSP语法及JSTL标签
域内用户访问域外samba服务器用户名密码错误
Golang implements Ping connectivity detection case through exec module
给yarn配置国内镜像加速器
Pytorch学习记录(九):Pytorch中卷积神经网络
jdbc入门\获取数据库连接\使用PreparedStatement
对象转map
mysql中duplicate key update
Solid contract DoS attack
‘EddiesObservations‘ object has no attribute ‘filled‘
XXL job pit guide XXL RPC remoting error (connect timed out)
MySQL lock mechanism
MySql基础狂神说
Pytorch學習記錄(十三):循環神經網絡((Recurrent Neural Network)
编写一个自己的 RedisTemplate
SQL基础:初识数据库与SQL-安装与基本介绍等—阿里云天池
filebrowser实现私有网盘
PHP处理json_decode()解析JSON.stringify