redis key过期 业务处理
This commit is contained in:
@@ -60,8 +60,6 @@ import java.util.Map;
|
||||
@EnableConfigurationProperties(RedisProperties.class)
|
||||
public class RedisConfig extends CachingConfigurerSupport {
|
||||
|
||||
@Autowired
|
||||
private RedisKeyExpirationListener redisKeyExpirationListener;
|
||||
|
||||
/**
|
||||
* 设置 redis 数据默认过期时间,默认2小时
|
||||
@@ -100,15 +98,6 @@ public class RedisConfig extends CachingConfigurerSupport {
|
||||
return template;
|
||||
}
|
||||
|
||||
//redis key失效监听
|
||||
@Bean
|
||||
public RedisMessageListenerContainer redisMessageListenerContainer(RedisConnectionFactory connectionFactory) {
|
||||
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
|
||||
container.setConnectionFactory(connectionFactory);
|
||||
// 监听特定键的过期事件
|
||||
container.addMessageListener(redisKeyExpirationListener, new PatternTopic("__keyevent@0__:expired"));
|
||||
return container;
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义缓存key生成策略,默认将使用该策略
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
package cn.ysk.cashier.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.Message;
|
||||
import org.springframework.data.redis.connection.MessageListener;
|
||||
|
||||
@Configuration
|
||||
public class RedisKeyExpirationListener implements MessageListener {
|
||||
|
||||
@Override
|
||||
public void onMessage(Message message, byte[] pattern) {
|
||||
String expiredKey = new String(message.getBody());
|
||||
System.out.println("过期的Key为: " + expiredKey);
|
||||
// 在这里添加处理键过期事件的逻辑
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user