我使用redis消息发布/订阅来监听密钥过期。前10分钟内工作正常。在此之后,侦听器在我重新启动服务器之前无法获取任何事件。我想那里的连接断开了。代码如下:
// Configuration
@Bean
RedisMessageListenerContainer keyExpirationListenerContainer(ExpirationListener expirationListener) {
RedisMessageListenerContainer listenerContainer = new RedisMessageListenerContainer();
listenerContainer.setConnectionFactory(lettuceConnectionFactory());
listenerContainer.addMessageListener(expirationListener, new PatternTopic("__keyevent@*__:expired"));
listenerContainer.setErrorHandler(e -> log.error("There was an error in redis key expiration listener container", e));
return listenerContainer;
}
// Usage
@Component
@Slf4j
@AllArgsConstructor
public class ExpirationListener implements MessageListener {
@Override
public void onMessage(Message message, byte[] bytes) {
String key = new String(message.getBody());
log.info("expired redis key: {}", key);
}
}
我希望能得到你们的帮助。谢谢您!
暂无答案!
目前还没有任何答案,快来回答吧!