0%

springboot接收redis消息过期通知

redis连接配置:

 @Bean
RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory) {
    RedisMessageListenerContainer container = new RedisMessageListenerContainer();
    container.setConnectionFactory(connectionFactory);
    return container;
}

消息监听器:

@Component
public class RedisCallBack extends KeyExpirationEventMessageListener {

    public RedisCallBack(RedisMessageListenerContainer listenerContainer) {
        super(listenerContainer);
    }

    @Override
    public void onMessage(Message message, byte[] pattern) {
        System.out.println("过期key:" + message.toString());
    }
}