推荐学习书目
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 · Oct 12, 2015 · 5021 views
    This topic created in 3893 days ago, the information mentioned may be changed or developed.
    如题,现在有一个主 redis ,一个从 redis ,如何优雅的实现主挂了,自动切换到从了。

    我想过改 redis-py 的 connectpool
    9 replies    2015-10-13 13:11:46 +08:00
    vivisidea
        1
    vivisidea  
       Oct 12, 2015
    主从切换不是 redis-sentinel 的事情么, redis-client 支持 sentinel 应该就可以了吧
    sagrada
        2
    sagrada  
       Oct 12, 2015
    连主的时候 try 一下,报错就连从
    wshcdr
        3
    wshcdr  
       Oct 12, 2015
    主从是数据库自己内部的事儿,对你而言,是同一个地址
    UBER
        4
    UBER  
       Oct 12, 2015 via iPhone
    为什么我想说楼主应该从 DNS 层面考虑自动切换呢?
    strahe
        5
    strahe  
       Oct 12, 2015
    你不用考虑主从吧, redis 内部实现主从
    paulw54jrn
        6
    paulw54jrn  
       Oct 12, 2015
    之前用 ElasticCache 没找到内部实现主从切换(主写从读).. 随手写了下:
    https://gist.github.com/PaulLiang1/b145c7219773916bc701
    xdz0611
        7
    xdz0611  
       Oct 12, 2015
    redis 挂虚 ip ,主从使用同一个 ip 是靠谱的方案呢。
    alexapollo
        8
    alexapollo  
       Oct 12, 2015
    jiakon
        9
    jiakon  
       Oct 13, 2015
    用 keepalived 吧。 python 连接 keepvlived 生成的 vip 就行。
    keepalived 可以去检测两个 redis ,实现故障自动切换。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2546 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 16:09 · PVG 00:09 · LAX 09:09 · JFK 12:09
    ♥ Do have faith in what you're doing.