0

What I want to do is to failover Redis with Django, but cannot find the way to do it.

What I've setup is as follows:

  • I'm using Redis as a session backend.
  • I've setup two Redis servers in master-slave relationship that when master fails, slave automatically becomes master (using Sentinnel)

I setup settings.py like this

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"

I want Django to use only the master normally, and switch automatically to slave when it can't connect to the master.

How could I do this by editing settings.py or should I take another way around?

user2875308
  • 451
  • 5
  • 14
  • You could create a script (called by your polling system) that would update `settings.py` with the slave server info, then restart your application. Alternatively, you could have multiple copies of `settings.py`, `settings.py.slave`, `settings.py.master`, then have your polling system overwrite your `settings.py` with the appropriate file. – Dirty Penguin Dec 08 '15 at 03:30

1 Answers1

1

I would probably go with something like https://github.com/KabbageInc/django-redis-sentinel/blob/master/README.md which adds sentinel support to the Django Redis plugin. There may be others more suitable, this was top of the list in a Google search for Django sentinel.

The Real Bill
  • 14,884
  • 8
  • 37
  • 39