V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
ingin
V2EX  ›  Python

Python 监听 redis 的 channel 问题

  •  
  •   ingin · Nov 19, 2018 · 2228 views
    This topic created in 2729 days ago, the information mentioned may be changed or developed.

    在 flask 项目中,单独开一个进程来订阅第三方 redis 的 channel,代码如下

    r = redis.Redis(connection_pool=pool)
    p = r.pubsub()
    p.subscribe([channel])
    for sub in p.listen():
        print(sub)
    

    在项目启动之后该监听服务正常,但是在十几分钟之后该服务不再工作,有老哥知道原因吗?是不是有个配置能够保证该 redis 连接为长连接。

    1 replies    2018-11-19 16:41:11 +08:00
    xpresslink
        1
    xpresslink  
       Nov 19, 2018
    再弄个线程,用 timer 每 5 分钟 keepalive 一下。:-)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1238 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 17:29 · PVG 01:29 · LAX 10:29 · JFK 13:29
    ♥ Do have faith in what you're doing.