当前位置:网站首页>Redis configuration class redisconfig
Redis configuration class redisconfig
2022-07-07 01:56:00 【Novice Zhang~】
package com.menglar.soap.item.common.config;
import com.alibaba.fastjson.support.spring.GenericFastJsonRedisSerializer;
import com.menglar.soap.item.common.listener.KeyExpiredListener;
import org.springframework.beans.factory.annotation.Autowired;
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.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.serializer.GenericToStringSerializer;
/** * @program: soap-item_v2 * @description: redis Configuration class * @author: ZhangRiTian * @create: 2021-10-25 09:24 */
@Configuration
public class RedisConfig {
@Autowired
private RedisConnectionFactory redisConnectionFactory;
/** * Listener connection factory class */
@Bean
public RedisMessageListenerContainer redisMessageListenerContainer() {
RedisMessageListenerContainer redisMessageListenerContainer = new RedisMessageListenerContainer();
redisMessageListenerContainer.setConnectionFactory(redisConnectionFactory);
return redisMessageListenerContainer;
}
/** * Monitor */
@Bean
public KeyExpiredListener keyExpiredListener() {
return new KeyExpiredListener(this.redisMessageListenerContainer());
}
@Bean
public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(redisConnectionFactory);
// Use GenericFastJsonRedisSerializer Replace default serialization
GenericFastJsonRedisSerializer genericFastJsonRedisSerializer = new GenericFastJsonRedisSerializer();
// Set up key and value Serialization rules
redisTemplate.setKeySerializer(new GenericToStringSerializer<>(Object.class));
redisTemplate.setValueSerializer(genericFastJsonRedisSerializer);
// Set up hashKey and hashValue Serialization rules
redisTemplate.setHashKeySerializer(new GenericToStringSerializer<>(Object.class));
redisTemplate.setHashValueSerializer(genericFastJsonRedisSerializer);
// Set up supporting things
redisTemplate.setEnableTransactionSupport(true);
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
}
边栏推荐
- AcWing 346. 走廊泼水节 题解(推公式、最小生成树)
- js如何快速创建一个长度为 n 的数组
- AcWing 345. 牛站 题解(floyd的性质、倍增)
- ZOJ problem set – 2563 long dominoes [e.g. pressure DP]
- Appium基础 — Appium Inspector定位工具(一)
- How did partydao turn a tweet into a $200million product Dao in one year
- AcWing 1140. Shortest network (minimum spanning tree)
- 使用nodejs完成判断哪些项目打包+发版
- Today's question -2022/7/4 modify string reference type variables in lambda body
- 【唯一】的“万字配图“ | 讲透【链式存储结构】是什么?
猜你喜欢

Centros 8 installation MySQL Error: The gpg Keys listed for the "MySQL 8.0 Community Server" repository are already ins

C语言关于链表的代码看不懂?一篇文章让你拿捏二级指针并深入理解函数参数列表中传参的多种形式

Appium基础 — Appium Inspector定位工具(一)

ROS learning (21) robot slam function package -- installation and testing of orbslam

鼠标右键 自定义

【唯一】的“万字配图“ | 讲透【链式存储结构】是什么?

制作带照明的DIY焊接排烟器

Ros Learning (23) Action Communication Mechanism

Analyze "C language" [advanced] paid knowledge [II]

Mongodb checks whether the table is imported successfully
随机推荐
2022/0524/bookstrap
Treadpoolconfig thread pool configuration in real projects
CISP-PTE之命令注入篇
Box stretch and pull (left-right mode)
糊涂工具类(hutool)post请求设置body参数为json数据
ROS学习(23)action通信机制
Appium自动化测试基础 — uiautomatorviewer定位工具
New job insights ~ leave the old and welcome the new~
Flir Blackfly S 工业相机:通过外部触发实现多摄像头同步拍摄
Add PDF Title floating window
Gin 入门实战
Baidu flying general BMN timing action positioning framework | data preparation and training guide (Part 1)
ROS学习(26)动态参数配置
The foreground downloads network pictures without background processing
AcWing 361. Sightseeing cow problem solution (SPFA seeking positive ring)
How can I code for 8 hours without getting tired.
Comparison of picture beds of free white whoring
ROS学习(21)机器人SLAM功能包——orbslam的安装与测试
Right mouse button customization
JS es5 peut également créer des constantes?