I have the following code, to handle when a key expire in redis:
r.config_set('notify-keyspace-events', 'Ex')
pubsub.psubscribe(**{"__keyevent@0__:expired": event_handler})
pubsub.run_in_thread(sleep_time=0.01)
def event_handler(msg):
try:
print(msg)
key = msg["data"].decode("utf-8")
print(key)
except Exception as e:
print(e)
The problem is that I am only getting the key, and not the value from the expired key.
Is there anyway of get that data?
Thanks
create another key, like "mykey.shadow" which actually has the expiration. When it expires, retrieve the real key and the stored value and then delete it.