1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| import redis
pool = redis.ConnectionPool(host='ip', port=6000, db="", password='') r = redis.StrictRedis(connection_pool=pool) p = r.pubsub() p.subscribe("RHINODEPTH", "RHINOTRADE") for item in p.listen(): print("Listen on channel : %s " % item['channel'].decode()) if item['type'] == 'message': data = item['data'].decode() print("From %s get message : %s" % (item['channel'].decode(), item['data'].decode())) if item['data'] == 'over': print(item['channel'].decode(), '停止发布') break
|