当前位置:网站首页>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
边栏推荐
- 多线程与高并发(1)——线程的基本知识(实现,常用方法,状态)
- io.lettuce.core.RedisCommandExecutionException: ERR wrong number of arguments for ‘auth‘ command
- No.1.#_ 6 Navicat shortcuts
- Fletter next generation graphics renderer impaller
- SQL注入
- Common status codes
- io. lettuce. core. RedisCommandExecutionException: ERR wrong number of arguments for ‘auth‘ command
- Insert picture in freemark
- 建表到页面完整实例演示—联表查询
- JSP语法及JSTL标签
猜你喜欢

Fletter next generation graphics renderer impaller

PreparedStatement防止SQL注入

Ptorch learning record (XIII): recurrent neural network

Differences between sea level anatomy and sea surface height anatomy

实操—Nacos安装与配置

Anaconda

多线程与高并发(3)——synchronized原理

Navicate连接oracle(11g)时ORA:28547 Connection to server failed probable Oeacle Net admin error

MySQL的锁机制

JVM series (3) -- memory allocation and recycling strategy
随机推荐
Pytorch学习记录(五):反向传播+基于梯度的优化器(SGD,Adagrad,RMSporp,Adam)
mysql如何将存储的秒转换为日期
Batch import of orange single micro service
PyQy5学习(四):QAbstractButton+QRadioButton+QCheckBox
Mysql 查询使用\G,列转行
图解HashCode存在的意义
Multithreading and high concurrency (2) -- detailed explanation of synchronized usage
xxl-job采坑指南xxl-rpc remoting error(connect timed out)
DBCP使用
mysql sql优化之Explain
线程的底部实现原理—静态代理模式
MySQL transaction
Ora: 28547 connection to server failed probable Oracle net admin error
实操—Nacos安装与配置
Pytorch learning record (IX): convolutional neural network in pytorch
delete和truncate
Pytorch learning record (XI): data enhancement, torchvision Explanation of various functions of transforms
mysql中duplicate key update
mysql-触发器、存储过程、存储函数
Golang implements Ping connectivity detection case through exec module