当前位置:网站首页>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 904. Wormhole solution (SPFA for negative rings)
- JS Es5 can also create constants?
- JVM memory model
- Compile command line terminal swift
- CISP-PTE实操练习讲解(二)
- ROS learning (26) dynamic parameter configuration
- Telnet,SSH1,SSH2,Telnet/SSL,Rlogin,Serial,TAPI,RAW
- ZOJ Problem Set – 2563 Long Dominoes 【如压力dp】
- 盒子拉伸拉扯(左右模式)
- 场景实践:基于函数计算快速搭建Wordpress博客系统
猜你喜欢
随机推荐
AcWing 361. 观光奶牛 题解(spfa求正环)
Drag to change order
ROS学习(23)action通信机制
The GPG keys listed for the "MySQL 8.0 community server" repository are already ins
Threadlocalutils (tool class IV)
ROS learning (24) plugin
Telnet,SSH1,SSH2,Telnet/SSL,Rlogin,Serial,TAPI,RAW
Analyze "C language" [advanced] paid knowledge [i]
Analyze "C language" [advanced] paid knowledge [End]
mongodb查看表是否导入成功
454-百度面经1
C语言关于链表的代码看不懂?一篇文章让你拿捏二级指针并深入理解函数参数列表中传参的多种形式
dvajs的基础介绍及使用
【唯一】的“万字配图“ | 讲透【链式存储结构】是什么?
Scenario practice: quickly build wordpress blog system based on function calculation
鼠标右键 自定义
拖拽改变顺序
ZOJ Problem Set – 2563 Long Dominoes 【如压力dp】
centos8安装mysql报错:The GPG keys listed for the “MySQL 8.0 Community Server“ repository are already ins
Ros Learning (23) Action Communication Mechanism








