通过redis过期事件的监听,执行相应命令。(注意:因为监听只能得到key, 所以需要另外存储具体执行内容体)
另外记得修改redis配置: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