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:
redis-cli example
127.0.0.1:6379> get milan
(nil)
127.0.0.1:6379> keys *
1) "_kombu.binding.celeryev"
2) "_kombu.binding.celery"
3) "_kombu.binding.celery.pidbox"
127.0.0.1:6379> keys *
1) "_kombu.binding.celeryev"
2) "_kombu.binding.celery"
3) "_kombu.binding.celery.pidbox"
127.0.0.1:6379> get kranf
(nil)
127.0.0.1:6379>
And debug_tool
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.
What does happen? Can you show the exact commands you’re running? You believe the Django/Celery wiring is correct, are you seeing things like the application creating a task and the worker running it?
@DavidMaze I added redis-cli example and screenshot debug_tool. The problem is that I want to work with redis through the terminal to be sure that everything works, but even though redis works with django, the data is written out, but this data is not saved in the redis terminal in docker. For example, I’m trying to get get kranf, which I saved when entering the page in django, but there is no data, and if I do the get through the code in django itself on the views page, then there are no problems
Based on what you’ve shown, the Redis server is starting up,
redis-cli
can connect to it, and it seems like the Celery wiring is working. Can you provide an example of the code that isn’t working? (Why do you expect there to be more keys?)@DavidMaze I save the cache, that’s working, but in redis-cli i don’t see anything
def redis_check(request): cache.set('milan', 'man', timeout=None) key_exists = cache.get('milan') return HttpResponse(f'<html><body><h1>{key_exists}</h1></body></html>')