当前位置:网站首页>编写一个自己的 RedisTemplate
编写一个自己的 RedisTemplate
2022-04-23 05:43:00 【林仔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 {
// 编写自己的redisTemplate
@Bean
@SuppressWarnings("all")
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
// 我们为了自己开发方便,一般直接使用<String, Object>
RedisTemplate<String, Object> template = new RedisTemplate();
template.setConnectionFactory(factory);
// Json序列化配置
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 的序列化
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
// 配置具体的序列化方式
// key 采用String的序列化方式
template.setKeySerializer(stringRedisSerializer);
// hash 的key也采用String的序列化方式
template.setHashKeySerializer(stringRedisSerializer);
// value序列化的方式采用jackson
template.setValueSerializer(jackson2JsonRedisSerializer);
// hash的value序列化方式采用Jackson
template.setHashValueSerializer(jackson2JsonRedisSerializer);
template.afterPropertiesSet();
return template;
}
}
版权声明
本文为[林仔520]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_37955704/article/details/114915806
边栏推荐
- io. lettuce. core. RedisCommandExecutionException: ERR wrong number of arguments for ‘auth‘ command
- Add days to date
- C language - Spoof shutdown applet
- K/3 WISE系统考勤客户端日期只能选到2019年问题
- The list attribute in the entity is empty or null, and is set to an empty array
- js数字大写方法
- mysql实现主从复制/主从同步
- POI exports to excel, and the same row of data is automatically merged into cells
- Golang implements Ping connectivity detection case through exec module
- DBCP使用
猜你喜欢
MySQL的锁机制
Pilotage growth · ingenuity empowerment -- yonmaster developer training and pilotage plan is fully launched
多线程与高并发(1)——线程的基本知识(实现,常用方法,状态)
AcWing 836. Merge set (merge set)
引航成长·匠心赋能——YonMaster开发者培训领航计划全面开启
SQL注入
一文读懂当前常用的加密技术体系(对称、非对称、信息摘要、数字签名、数字证书、公钥体系)
橙单微服务之批量导入
Issue 36 summary of atcoder beginer contest 248
Transposed convolution
随机推荐
热键,界面可视化配置(界面交互)
Duplicate key update in MySQL
delete和truncate
Isosceles triangle - the 9th Lanqiao provincial competition - group C
实操—Nacos安装与配置
POI generates excel and inserts pictures
C语言——恶搞关机小程序
freemark中插入图片
Getting started with JDBC \ getting a database connection \ using Preparedstatement
框架解析1.系统架构简介
excel获取两列数据的差异数据
No.1.#_ 6 Navicat shortcuts
‘EddiesObservations‘ object has no attribute ‘filled‘
Transposed convolution
开发环境 EAS登录 license 许可修改
Flutter 新一代圖形渲染器 Impeller
K/3 WISE系统考勤客户端日期只能选到2019年问题
Understand the current commonly used encryption technology system (symmetric, asymmetric, information abstract, digital signature, digital certificate, public key system)
Fletter next generation graphics renderer impaller
创建企业邮箱账户命令