Home  >  Article  >  Backend Development  >  Manage scheduled tasks through reidis

Manage scheduled tasks through reidis

巴扎黑
巴扎黑Original
2016-12-03 10:14:501778browse

The main application scenarios are: one-time scheduled tasks with changing requirements.
Execute corresponding commands by monitoring redis expiration events. (Note: Because monitoring can only get the key, you need to store the specific execution content 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


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn