After connecting redis to django and docker, the data is not saved in redis-cli
I connected redis to django and did docker-compose, redis itself works, but if I want to connect to the terminal via docker exec -it redis redis-cli, then it connects, but I can’t get any data and if I write the keys * command, then no data either (except for celery)
version: '3.8'
services:
web:
build: .
container_name: django
ports:
- "8000:8000"
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/app
env_file:
- .env
environment:
- DEBUG=1
- DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1
- CELERY_BROKER=redis://redis:6379/0
- CELERY_BACKEND=redis://redis:6379/0
- REDIS_HOST=redis
depends_on:
- db
- redis
links:
- db:db
db:
container_name: postgres
image: postgres
volumes:
- ./data/postgres_data:/var/lib/postgresql/data
environment:
- POSTGRES_DB=${BD_NAME}
- POSTGRES_USER=${BD_USER}
- POSTGRES_PASSWORD=${BD_PASSWORD}
- POSTGRES_HOST_AUTH_METHOD=trust
expose:
- '5432'
redis:
image: "redis:alpine"
restart: always
container_name: redis
command: redis-server
ports:
- 6379:6379
celery:
build: .
command: celery -A wishes worker -l INFO
volumes:
- .:/app
depends_on:
- web
- redis
- db
environment:
- CELERY_BROKER=redis://redis:6379/0
- CELERY_BACKEND=redis://redis:6379/0
volumes:
postgres_data:
If the Redis is empty its probably because you forgot to set the BACKEND of CACHES setting to django.core.cache.backends.redis.RedisCache.
The default backend provided for CACHES is django.core.cache.backends.locmem.LocMemCache that store cache data into memory.