python连接redis发布消息

发布信息
import redis
import time


class RedisPub():
    def __init__(self):
        pool = redis.ConnectionPool(host='127.0.0.0', port='6379', password='adc123') #连接redis
        self._conn = redis.StrictRedis(connection_pool=pool)
        self.pub_chan = 'chan_test'

    def public(self):
        msg = ('要发布的信息内容')
        
    self._conn.publish(self.pub_chan, msg) #发布信息

if __name__ == '__main__':
    R = RedisPub()
    R.public()

你可能感兴趣的:(python连接redis发布消息)