Manage timed tasks through reidis

The main application scenarios are: one-time scheduled tasks with changing requirements.

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

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327093992&siteId=291194637