zoukankan      html  css  js  c++  java
  • redis pipeset发布订阅

    #!/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

  • 相关阅读:
    无重复字符的最长子串
    有效的括号
    最长公共前缀
    罗马数字转整数
    Android解析JSON数据异步加载新闻图片
    回文数
    Java从Json获得数据的四种方式
    JavaMD5加密工具类
    div模仿select效果二:带搜索框
    BG雪碧图制作要求
  • 原文地址:https://www.cnblogs.com/zhangmingda/p/9498537.html
Copyright © 2011-2022 走看看