当前位置:网站首页>redis监听key过期事件
redis监听key过期事件
2022-04-22 06:26:00 【小飞机爱旅游】
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class RedisKeyExpirationListener extends KeyExpirationEventMessageListener {
public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
super(listenerContainer);
}
/**
* 针对redis数据失效事件,进行数据处理
* @param message
* @param pattern
*/
@Override
public void onMessage(Message message, byte[] pattern) {
String expiredKey = message.toString();
System.out.print("123213123123123=====》"+expiredKey);
}
}
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
@Configuration
public class RedisListenerConfig {
@Bean
RedisMessageListenerContainer redisMessageListenerContainer(RedisConnectionFactory connectionFactory) {
RedisMessageListenerContainer redisMessageListenerContainer = new RedisMessageListenerContainer();
redisMessageListenerContainer.setConnectionFactory(connectionFactory);
return redisMessageListenerContainer;
}
}
版权声明
本文为[小飞机爱旅游]所创,转载请带上原文链接,感谢
https://blog.csdn.net/lc15568886496/article/details/119571863
边栏推荐
猜你喜欢
随机推荐
测试题(2)
Opportunity interview questions
QT广告屏(多显示器分屏+全屏显示图片)
Why is MySQL self incrementing primary key not continuous?
Xshell连接虚拟机
Easylogging++日志库
Unity 知识点(常用核心类)
Use of branches in C #
JS realizes web page special effects on PC and mobile terminals
Crawler 51job
Questions d'entrevue de l'unit é
同一个类中@Transactional 事务传播
Information System Project Manager - Chapter IV overall project management
Inverse Polish quaternion
MFC常用格式转换及函数
Multithreading (thread class, runnable interface, callable interface, synchronized, lock, thread pool)
JS - 精度问题
Rt-thread [二] 系统初始化流程
多线程(线程通信【生产者与消费者】)
从零学C语言 【一】基本概念
![Rt-thread [一] 创建工程](/img/cd/9a2a9c7381caaf150b3700e348e38a.png)






![Rt-thread [二] 系统初始化流程](/img/46/6e2942e4c18c0220378050205e6528.png)

