当前位置:网站首页>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;
}
}
边栏推荐
- Curl command
- ROS学习(21)机器人SLAM功能包——orbslam的安装与测试
- 百度飞将BMN时序动作定位框架 | 数据准备与训练指南 (下)
- The cradle of eternity
- Let's see how to realize BP neural network in Matlab toolbox
- dvajs的基础介绍及使用
- Set up [redis in centos7.x]
- AcWing 1141. LAN problem solving (kruskalkruskal finding the minimum spanning tree)
- Analyze "C language" [advanced] paid knowledge [II]
- 2022/0524/bookstrap
猜你喜欢
Let's see how to realize BP neural network in Matlab toolbox
制作带照明的DIY焊接排烟器
Cat recycling bin
刨析《C语言》【进阶】付费知识【一】
AcWing 1148. Secret milk transportation problem solution (minimum spanning tree)
开发中对集合里面的数据根据属性进行合并数量时犯的错误
js如何快速创建一个长度为 n 的数组
场景实践:基于函数计算快速搭建Wordpress博客系统
sql中批量删除数据---实体中的集合
Baidu flying general BMN timing action positioning framework | data preparation and training guide (Part 1)
随机推荐
2022 system integration project management engineer examination knowledge point: Mobile Internet
Add PDF Title floating window
AcWing 1141. 局域网 题解(kruskalkruskal 求最小生成树)
centos8安装mysql报错:The GPG keys listed for the “MySQL 8.0 Community Server“ repository are already ins
C语言关于链表的代码看不懂?一篇文章让你拿捏二级指针并深入理解函数参数列表中传参的多种形式
Blue Bridge Cup 2022 13th provincial competition real topic - block painting
According to the analysis of the Internet industry in 2022, how to choose a suitable position?
WCF基金会
hdu 4661 Message Passing(木DP&amp;组合数学)
How did partydao turn a tweet into a $200million product Dao in one year
Make DIY welding smoke extractor with lighting
Box stretch and pull (left-right mode)
Treadpoolconfig thread pool configuration in real projects
AcWing 904. 虫洞 题解(spfa求负环)
Compile command line terminal swift
MySQL's most basic select statement
New job insights ~ leave the old and welcome the new~
永久的摇篮
【唯一】的“万字配图“ | 讲透【链式存储结构】是什么?
AcWing 345. Cattle station solution (nature and multiplication of Floyd)