zoukankan      html  css  js  c++  java
  • [Redis-Python]发布订阅通过Redis异步发送邮件

    接收订阅

    #!/usr/bin/env pyhton
    # coding:utf-8
    # @Time     : 2020-02-16 21:36
    # @Author   : LeoShi
    # @Site     : 
    # @File     : redis_demo.py
    # @Software : MacOS Python 3.7
    
    import redis
    
    # 创建链接
    # 返回 b'peigy2020'
    # redis_connect = redis.Redis(host='172.16.1.111', port=6379, password='password')
    # decode_responses=True 返回字符串
    redis_connect = redis.Redis(host='172.16.1.111', port=6379, password='password', decode_responses=True)
    
    # 接收订阅
    catch = redis_connect.pubsub()
    # 接收频道
    catch.subscribe('email')
    while 1:
        for item in catch.listen():
            if item['type'] == 'message':
                data = item['data']
                print(data)
                # 发送邮件
    

    发布订阅

    #!/usr/bin/env pyhton
    # coding:utf-8
    # @Time     : 2020-02-16 22:19
    # @Author   : LeoShi
    # @Site     : 
    # @File     : redis_pulish.py
    # @Software : MacOS Python 3.7
    
    import redis
    
    # 建立连接
    redis_connect = redis.Redis(host='172.16.1.111', port=6379, password='password', decode_responses=True)
    
    # 发布订阅
    for i in range(3):
        redis_connect.publish('email','This is message{}'.format(i))
    

    接收信息结果

    This is message0
    This is message1
    This is message2
    
  • 相关阅读:
    Unit Vector Compression
    PT, BPT, VCM
    Major Performance Impacts

    SAH Benchmarks Of Natural History Museum Scene
    图标变换图片---轮播切换
    弹出层--弹框
    Git for windows 中文乱码解决方案
    在CentOS上安装Git
    Git 的基本配置
  • 原文地址:https://www.cnblogs.com/leoshi/p/12319261.html
Copyright © 2011-2022 走看看