![](/style/images/good.png)
6
![](/style/images/bad.png)
python 模块 | redis
source link: https://benpaodewoniu.github.io/2022/11/20/python181/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
简单的介绍这个库的一些基本用法。
订阅/推送
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')
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK