0%

python 模块 | redis

简单的介绍这个库的一些基本用法。

订阅/推送

订阅

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
# p.unsubscribe('spub')
请我喝杯咖啡吧~