ITeye博客

通过reidis管理定时任务

iyuan · 2016-09-14 14:31 · python · redis · 开源软件 · Redis · Python · Markdown

主要应用场景为:有变动需求的一次性定时任务。

通过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

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。