[Django]-Django won't connect to Redis Docker container

5👍

The host name is what you call the container that runs Redis. For example, if your docker-compose contains something like this:

cache:
    image: redis:3.2.6

then, you need to set the configuration to connect to cache:6379

0👍

Just adding to the below answer, the probable issue while using docker compose is referring to localhost directly. We must use the service name instead.

So if you are using in docker compose, redis like this:

cache:
  image: redis:7-alpine

Then in settings.py, refer to the service like this:

CACHES = {
        "default": {
            "BACKEND": "django_redis.cache.RedisCache",
            "LOCATION": "redis://cache:6379/1", # Note the cache
            "OPTIONS": {
                "CLIENT_CLASS": "django_redis.client.DefaultClient",
            },
        }
    }

Leave a comment