74 字
1 分钟
redis订阅python代码
2019-02-28
class Listener(object):
"""
监听器,用于监听Redis订阅的data
"""
def __init__(self):
# self.r = redis.Redis(host='139.198.4.56', port='6379')
# redis_client为redis连接设置
self.redis_client = redis_client
self.crawl_seeds = self.redis_client.pubsub()
self.crawl_seeds.subscribe('content')
logging.info("连接到Redis...")
def listen(self):
for item in self.crawl_seeds.listen():
if item['type'] != 'message':
continue
meta = str(item['data'], encoding='utf-8')
logging.info('收:%s ' % json.loads(meta).get('content', '').strip())

用日志打印接受结果

redis订阅python代码
https://gilgameshzzz.github.io/posts/redis订阅python代码/
作者
Amadeus
发布于
2019-02-28
许可协议
CC BY-NC-SA 4.0