Through the monitoring of the redis expiration event, the corresponding command is executed. (Note: Because the monitor can only get the key, the specific execution content needs to be stored separately)
Also remember to modify the redis configuration: notify-keyspace-events Ex
import redis rdc = redis.StrictRedis() pubsub = rdc.pubsub() pubsub.psubscribe("__keyevent@0__:expired") while pubsub.subscribed: msg = pubsub.get_message() if msg: print msg