/**
* redis事件监听
* @author YOLO
* @date 2020-11-26
* @param
* @return
*/
@Configuration
public class RedisListenerConfig {
@Bean
RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory) {
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
return container;
}
}
package com.github.wxiaoqi.security.yibum.listener;
import com.github.wxiaoqi.security.common.util.DateUtil;
import com.github.wxiaoqi.security.yibum.entity.Activity;
import com.github.wxiaoqi.security.yibum.mapper.ActivityMapper;
import com.github.wxiaoqi.security.yibum.mapper.YsBrandsApplyMapper;
import com.github.wxiaoqi.security.yibum.util.SendWxTemplateMessage;
import com.github.wxiaoqi.security.yibum.vo.WxMessageVo;
import com.github.wxiaoqi.security.yibum.vo.WxTemplateMessageVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
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;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* reids过期监听器
*
* @param
* @author YOLO
* @date 2020-11-26
* @return
*/
@Component
@Slf4j
public class RedisKeyExpirationListener extends KeyExpirationEventMessageListener {
@Autowired
private YsBrandsApplyMapper ysBrandsApplyMapper;
@Autowired
private ActivityMapper activityMapper;
public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
super(listenerContainer);
}
/**
* redis数据失效事件,进行数据处理
*
* @param message
* @param pattern
*/
@Override
public void onMessage(Message message, byte[] pattern) {
// message.toString()------获取失效的key
String expiredKey = message.toString();
log.info("===========>key失效:" + expiredKey);
}
}
redis 配置的 notify-keyspace-events Ex打开