当前位置:网站首页>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;
}
}
边栏推荐
- Input and output of C language pointer to two-dimensional array
- AcWing 1141. 局域网 题解(kruskalkruskal 求最小生成树)
- Use nodejs to determine which projects are packaged + released
- AcWing 346. Solution to the problem of water splashing festival in the corridor (deduction formula, minimum spanning tree)
- ROS learning (24) plugin
- LeetCode. Sword finger offer 62 The last remaining number in the circle
- Blue Bridge Cup 2022 13th provincial competition real topic - block painting
- 场景实践:基于函数计算快速搭建Wordpress博客系统
- Recognition of C language array
- WCF Foundation
猜你喜欢
随机推荐
Curl command
刨析《C语言》【进阶】付费知识【一】
[unique] what is the [chain storage structure]?
AcWing 1140. 最短网络 (最小生成树)
Shell script quickly counts the number of lines of project code
Unicode string converted to Chinese character decodeunicode utils (tool class II)
IDEA常用的快捷键
AcWing 345. Cattle station solution (nature and multiplication of Floyd)
我如何编码8个小时而不会感到疲倦。
AcWing 361. 观光奶牛 题解(spfa求正环)
百度飞将BMN时序动作定位框架 | 数据准备与训练指南 (上)
Public key \ private SSH avoid password login
C语言关于链表的代码看不懂?一篇文章让你拿捏二级指针并深入理解函数参数列表中传参的多种形式
百度飞将BMN时序动作定位框架 | 数据准备与训练指南 (下)
Long press the button to execute the function
WCF基金会
AcWing 1142. Busy urban problem solving (minimum spanning tree)
CISP-PTE之命令注入篇
centos8 用yum 安装MySQL 8.0.x
New job insights ~ leave the old and welcome the new~