当前位置:网站首页>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;
}
}
边栏推荐
- Appium自动化测试基础 — uiautomatorviewer定位工具
- [unique] what is the [chain storage structure]?
- 鼠标右键 自定义
- Reptile practice (VI): novel of climbing pen interesting Pavilion
- ROS learning (25) rviz plugin
- Unicode string converted to Chinese character decodeunicode utils (tool class II)
- 拖拽改变顺序
- 设置Wordpress伪静态连接(无宝塔)
- mysqlbackup 还原特定的表
- Appium foundation - appium inspector positioning tool (I)
猜你喜欢
New job insights ~ leave the old and welcome the new~
ROS learning (24) plugin
我如何编码8个小时而不会感到疲倦。
The cradle of eternity
Baidu flying general BMN timing action positioning framework | data preparation and training guide (Part 1)
开发中对集合里面的数据根据属性进行合并数量时犯的错误
AcWing 361. 观光奶牛 题解(spfa求正环)
AcWing 1148. Secret milk transportation problem solution (minimum spanning tree)
Analyze "C language" [advanced] paid knowledge [End]
Appium automation test foundation uiautomatorviewer positioning tool
随机推荐
糊涂工具类(hutool)post请求设置body参数为json数据
ROS learning (24) plugin
Scenario practice: quickly build wordpress blog system based on function calculation
ROS学习(22)TF变换
2022 system integration project management engineer examination knowledge point: Mobile Internet
AcWing 345. 牛站 题解(floyd的性质、倍增)
Introduction to microservice architecture
AcWing 345. Cattle station solution (nature and multiplication of Floyd)
How to use strings as speed templates- How to use String as Velocity Template?
ROS学习(十九)机器人SLAM功能包——cartographer
字符串转成日期对象
JS ES5也可以創建常量?
Ds-5/rvds4.0 variable initialization error
JS how to quickly create an array with length n
盒子拉伸拉扯(左右模式)
Blue Bridge Cup 2022 13th provincial competition real topic - block painting
uva 1401 dp+Trie
CISP-PTE实操练习讲解(二)
设置Wordpress伪静态连接(无宝塔)
AcWing 1140. 最短网络 (最小生成树)