V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
larkifly
V2EX  ›  Python

python redis 连接超时,可能是什么原因了?

  •  
  •   larkifly · 2016-02-04 11:13:11 +08:00 · 5191 次点击
    这是一个创建于 3003 天前的主题,其中的信息可能已经有所发展或是发生改变。
    redis 的日志级别是 notice ,查看 timeout 是, redis 日志没有更新,依然是启动时的日志。

    重启 python 程序,又能连上了,中间 redis 没有做任何改动或者重启。

    redis 和 python 程序在一个内网,不同机器。
    6 条回复    2016-02-04 15:37:17 +08:00
    aisk
        1
    aisk  
       2016-02-04 11:43:36 +08:00
    redis 当时是不是 CPU 跑满了?
    thinsky
        2
    thinsky  
       2016-02-04 11:48:09 +08:00
    可能是连接数达到上限?
    iyaozhen
        3
    iyaozhen  
       2016-02-04 12:06:49 +08:00
    应该是 redis 主动断掉了不活跃的连接。不知到你是连上 redis 进行什么操作,如果是 pub/sub 则需要在客户端连接时设置一个类似 read_timeout=-1 的东西。 PHP 的还需这样: ini_set(‘ default_socket_timeout ’, -1)。不过一般的话设置 redis timeout=0 就行了。
    mckelvin
        4
    mckelvin  
       2016-02-04 15:04:10 +08:00
    Redis 的原因,或者 Redis 到 Python 程序中间的网络原因(比如网络延迟)。

    Python 程序用的 Redis 客户端去兼容下断线重连比较好?

    另外建议给机器和 Redis 集群都加上系统指标方便查问题,比如 Redis 所在机器的 CPU, 网络, Redis 本地时延,远程时延。
    larkifly
        5
    larkifly  
    OP
       2016-02-04 15:36:03 +08:00
    @aisk cpu 内存 硬盘状态都是正常的
    larkifly
        6
    larkifly  
    OP
       2016-02-04 15:37:17 +08:00
    @iyaozhen timeout=0 这个已经设置了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2705 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 15:51 · PVG 23:51 · LAX 08:51 · JFK 11:51
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.