python 异步 订阅/发布 redis 设置超时时间

2017-12-19  本文已影响0人  Tofookie

代码:

pool = redis.ConnectionPool(host=REDIS_IP, port=REDIS_PORT, db=REDIS_DB, password=REDIS_PASSWORD)
rds = redis.StrictRedis(connection_pool=pool)

rds_sub = rds.pubsub()
rds_sub.subscribe('channel')
while True:
        res = rds_sub.get_message(timeout=8)
        if res and res['type'] == 'message':
              print(res)

上一篇 下一篇

猜你喜欢

热点阅读