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);
|
||||
// 在这里添加处理键过期事件的逻辑
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,34 +25,39 @@ public interface CacheKey {
|
||||
/**
|
||||
* 用户
|
||||
*/
|
||||
String USER_ID = "user::id:";
|
||||
String USER_ID = "user:id:";
|
||||
|
||||
/**
|
||||
* 激活码
|
||||
*/
|
||||
String ACT_CODE = "act_code:";
|
||||
/**
|
||||
* 数据
|
||||
*/
|
||||
String DATA_USER = "data::user:";
|
||||
String DATA_USER = "data:user:";
|
||||
/**
|
||||
* 菜单
|
||||
*/
|
||||
String MENU_ID = "menu::id:";
|
||||
String MENU_USER = "menu::user:";
|
||||
String MENU_ID = "menu:id:";
|
||||
String MENU_USER = "menu:user:";
|
||||
/**
|
||||
* 角色授权
|
||||
*/
|
||||
String ROLE_AUTH = "role::auth:";
|
||||
String ROLE_AUTH = "role:auth:";
|
||||
/**
|
||||
* 角色信息
|
||||
*/
|
||||
String ROLE_ID = "role::id:";
|
||||
String ROLE_ID = "role:id:";
|
||||
/**
|
||||
* 部门
|
||||
*/
|
||||
String DEPT_ID = "dept::id:";
|
||||
String DEPT_ID = "dept:id:";
|
||||
/**
|
||||
* 岗位
|
||||
*/
|
||||
String JOB_ID = "job::id:";
|
||||
String JOB_ID = "job:id:";
|
||||
/**
|
||||
* 数据字典
|
||||
*/
|
||||
String DICT_NAME = "dict::name:";
|
||||
String DICT_NAME = "dict:name:";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user