I'd like to register a command to run when a key is expired. This will allow me to delete items from an index when the associated key expires. I believe this can be done currently with keyspace events and a listener, but it would be nice to attach it to the expire request.

Since I am new to redis this might be out of scope for redis, if so, feel free to close. Thank you.

Comment From: ChenXiaoTemp

I also have the similar requirements.

I try to register a lister to watch EXPIRE event, but I found , if a key is expired, it will be removed after the EXPIRE event is triggered, but I want to watch the EXPIRE event and just clear some entries in the listener instead of deleting the keys(I mean it can remove or keep the entries depends on the return value from the event listener), is it possible? I think it may be a very useful feature.

Comment From: itamarhaber

Hello all,

This feature is currently not offered directly by Redis, but you can use keyspace notifications to subscribe to expiry events and trigger a piece of code in the subscriber.