3

I have a problem with the redis-sentinel connection.
I tried to connect redis-sentinel by using django-redis.

# redis connection factory
DJANGO_REDIS_CONNECTION_FACTORY = 'django_redis.pool.SentinelConnectionFactory'

# These sentinels are shared between all the examples, and are passed
# directly to Redis Sentinel. These can also be defined inline.
SENTINELS = [
    (env('REDIS_SENTINEL_IP_1'), 26379),
    (env('REDIS_SENTINEL_IP_2'), 26379),
    (env('REDIS_SENTINEL_IP_3'), 26379)
]

CACHES = {
    "default": {
        "BACKEND": env('DJANGO_CACHE_BACKEND_REDIS'),
        # THE HOSTNAME IN LOCATION is the primary (service/master) name
        # example : redis://dev-redis/db
        # example : redis://staging-redis/db
        "LOCATION": env('DJANGO_CACHE_LOCATION_REDIS'),
        "OPTIONS": {
            # django_redis.client.SentinelClient
            "CLIENT_CLASS": env('DJANGO_CACHE_CLIENT_CLASS'),
            "SENTINELS": SENTINELS,
            "SENTINEL_KWARGS":{'password':env('REDIS_PASSWORD_VALUE')},
            'PASSWORD': env('REDIS_PASSWORD_VALUE'),
            "CONNECTION_POOL_CLASS": "redis.sentinel.SentinelConnectionPool",
        },
        "KEY_PREFIX": "mapsvc"
    }
}

This is my settings.py.
and my environment is
on the kubernetes cluster
and the redis-sentinel is the node that can access the kubernetes cluster.

I tried to connect to the master in the kubernetes pod.
use this command redis-cli -h {master-ip} -p 6379 -a {password}
and it works! but django can't connect to redis-sentinel.

and it printed

ERROR - create_cache: AUTH <password> called without any password configured for the default user. Are you sure your configuration is correct?

The redis server version is 6.2.6.
and the django-redis version is 5.2.0.

and I also tried without "CONNECTION_POOL_CLASS": "redis.sentinel.SentinelConnectionPool",settings in settings.py.

Please help me.

Kim Juyeon
  • 31
  • 4
  • 1
    From the error log message it seems like django is trying to use [AUTH](https://redis.io/commands/auth/) command without a password. I would start checking `REDIS_PASSWORD_VALUE` environment variable because it may be empty. – usuario Jun 09 '22 at 06:46
  • I am already checking `REDIS_PASSWORD_VALUE` in container. and It has right variable. @usuario What can I do next? – Kim Juyeon Jun 10 '22 at 00:04

1 Answers1

0

I had the same problem when connecting to redis from my python code to docker. It turned out that I pulled a redis image with this command from the terminal:

docker run --name my-redis -p 6379:6379 -d redis

As you can see there wasn't a password configured.

I deleted this image and ran another one with this command:

docker run --name my-redis -p 6379:6379 -d redis --requirepass "MyPassWord"

Now when I initiate a redis instance using the password with the container running it connects successfully.

tdy
  • 36,675
  • 19
  • 86
  • 83
MMM9998
  • 1
  • 1