Feb 7, 2024
Spring data repositories already creating a listener for expired keys. the listener name is `KeyExpirationEventMessageListener`.
so you can activate it by configuring spring data redis repositories:
```
@EnableRedisRepositories(enableKeyspaceEvents = EnableKeyspaceEvents.ON_STARTUP)
```
and then you listen to the spring event that is emitted by that MessageListener
```
@EventListener
public void listener(RedisKeyExpiredEvent<MyCustomHash> evt) {
if (!(evt.getValue() instanceof MyCustomHash expired)) {
return;
}
log.info("{} ", expired);
}
```