0

我想做的是用 Django 对 Redis 进行故障转移,但找不到方法。

我的设置如下:

  • 我使用 Redis 作为会话后端。
  • 我在主从关系中设置了两台 Redis 服务器,当主服务器失败时,从服务器自动成为主服务器(使用 Sentinel)

我像这样设置settings.py

CACHES = {
    'default': {
        'BACKEND': 'redis_cache.RedisCache',
        'LOCATION':[
            "127.0.0.1",
            "IPofSlave"
        ],
        'OPTIONS': {
            'PASSWORD': "xxxxxxxx",
            'DB': 0,
        }
    }
}
SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
SESSION_CACHE_ALIAS = "default"

我希望django正常只使用master,连接不上master时自动切换到slave。

我怎么能通过编辑 settings.py 来做到这一点,还是应该采取另一种方式?

4

1 回答 1

1

我可能会选择像https://github.com/KabbageInc/django-redis-sentinel/blob/master/README.md这样的东西,它为 Django Redis 插件添加了哨兵支持。可能还有其他更合适的,这是 Google 搜索 Django sentinel 时的首选。

于 2015-12-09T02:42:17.130 回答