码迷,mamicode.com
首页 > 其他好文 > 详细

redis pipeset发布订阅

时间:2018-08-18 21:14:45      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:tran   parse   scribe   elf   hide   技术分享   public   zha   nsa   

技术分享图片
#!/usr/bin/env python
# Author:Zhangmingda
import redis,time

pool = redis.ConnectionPool(host=192.168.11.5,port=6379,db=2)
r = redis.Redis(connection_pool=pool)
pipe = r.pipeline(transaction=True)
pipe.set(age,22)
time.sleep(15)

pipe.execute()  #如果不执行,则不会执行pipe.set 即不会真正存值
pipeset
技术分享图片
#!/usr/bin/env python
# Author:Zhangmingda
#!/usr/bin/env python
# Author:Zhangmingda
import redis

class RedisHelper:
    def __init__(self):
        self.__conn = redis.Redis(host=192.168.11.5,port=6379)
        self.chan_sub = fm104.5
        self.chan_pub = fm104.5

    def public(self, msg): #发布消息用函数
        self.__conn.publish(self.chan_pub, msg)
        return True

    def subscribe(self): #接收消息用函数
        pub = self.__conn.pubsub()
        pub.subscribe(self.chan_sub)
        pub.parse_response()
        return pub

obj = RedisHelper()
redis_sub = obj.subscribe()
while True:
    msg = redis_sub.parse_response()
    print(msg)
redis_publish发布订阅
技术分享图片
#!/usr/bin/env python
# Author:Zhangmingda
import redis
class RedisHelper:
    def __init__(self):
        self.__conn = redis.Redis(host=192.168.11.5,port=6379)
        self.chan_sub = fm104.5
        self.chan_pub = fm104.5

    def public(self, msg): #发布消息用函数
        self.__conn.publish(self.chan_pub, msg)
        return True

server = RedisHelper()
server.public(hehe)
redis发布消息

 http://www.cnblogs.com/lianzhilei/p/5983673.html

redis pipeset发布订阅

标签:tran   parse   scribe   elf   hide   技术分享   public   zha   nsa   

原文地址:https://www.cnblogs.com/zhangmingda/p/9498537.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!