zoukankan      html  css  js  c++  java
  • python-redis-订阅和发布

    发布:redishelper.py
    import redis
    
    class RedisHelper:
    
        def __init__(self):
            self.__conn = redis.Redis(host='192.168.71.140')
            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
    

    订阅:redis_pub.py

    from redishelper import RedisHelper
    
    obi = RedisHelper()#实例化
    
    redis_sub = obi.subscribe()
    
    
    while True:
        msg =redis_sub.parse_response()
        print(msg)#收到就打印收不到就卡住
    
  • 相关阅读:
    CSS学习1
    三个和尚没水喝阅读笔记
    Javascript学习1

    mv 批量
    emacs 大小写转换
    too many open files
    成都定房
    有关重定向
    postgresql 数据库
  • 原文地址:https://www.cnblogs.com/fuyuteng/p/9283172.html
Copyright © 2011-2022 走看看