1

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

Tlaloc-ES
  • 4,825
  • 7
  • 38
  • 84

1 Answers1

0

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.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – xlmaster Feb 21 '23 at 07:07