'''
Redis pubsub, subscribe, listen, json.loads
'''
# pip install redis
import redis
import json
r = redis.Redis(host="localhost", port=6379, db=1) # connect to redis
p = r.pubsub(ignore_subscribe_messages=True) # set pubsub to ignore_subscrible_messages true
p.subscribe('topic-1', 'topic-2') # subscrible a topic
p.psubscribe('topic-*') # or psubscrible, pattern mode
for message in p.listen(): # listen what you just subscribed
# message is a type of dict, including four keys , type, pattern, channel and data
data = json.loads(message['data']) # extract data
print(type(data), data)
"""
Redis publish, json.dumps
"""
import redis
import json
db = redis.Redis(host="localhost", port=6379, db=1)
dict_data = {"name": "John", "gender": "male"}
json_data = json.dumps(dict_data)
db.publish("topic-1", json_data)
> {"name": "John", "gender": "male"}
今天的内容可能有点杂 进度好慢 zzzz 昨天讲到 for loop 但是正常人都不会只是像昨天那样...
昨天已经认识分隔符号 DELIMITER和STORED PROCEDURE建立语法, 建立出BMI小...
今天终於来到第30天了~就在今天,验证码小帮手将迎来总验收! 使用者加入好友 点击身份认证出现授权页...
Alex老师是为台湾CISSP资安教育训练开创新局的好老师! 愿Alex老师安息,一路好走! Al...
前言 Seaborn是比matplotlib功能更强大的绘图套件 是建立在matplotlib的基础...