0

Currently I am trying to integrate redis into my django project which is docker based. I was able to integrate redis using the DefaultClient but it doesn't work for SentinelClient

My settings.py looks like this:

DJANGO_REDIS_CONNECTION_FACTORY = 'django_redis.pool.SentinelConnectionFactory'


SENTINELS = [
    ('redis://redis-sentinel', 26379),
]

# redis-sentinel is the name of redis sentinel container

CACHES = {
    'default': {
        'BACKEND': 'django_redis.cache.RedisCache',
        'LOCATION': 'redis://redis-queue-1:6379',
        'OPTIONS': {
            'SENTINELS': SENTINELS,
            # django_redis.client.SentinelClient
            'CLIENT_CLASS': 'django_redis.client.SentinelClient',
            'CONNECTION_POOL_CLASS': 'redis.sentinel.SentinelConnectionPool',
        },
    }
}

It doesn't throw any exception, django just gets stuck on loading

Edit:

Upon trying to open shell and manually setting up a cache key I am presented with this error

redis.sentinel.MasterNotFoundError: No master found for 'redis-queue-1'

Although I used the same service name for default client and it works but presents an error for SentinelClient

Ahsan
  • 31
  • 1
  • 6

1 Answers1

0

Try using https://pypi.org/project/django-sentinel/

CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis_master/sentinel-host1:2639,sentinel-host2:2639/0"
        "OPTIONS": {
            "PASSWORD": 's3cret_passw0rd!',
            "CLIENT_CLASS": "django_sentinel.SentinelClient",
        }
    }
}