[Python] Why don't I see any Celery task result keys in Redis (even though tasks succeed)?

Discussão em 'Python' iniciado por Stack, Julho 24, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to run a basic Celery app with Redis as both the broker and the result backend. Everything works correctly—tasks are received, executed, and return the correct results—but I can't see any task-related keys in Redis. I'm using Redis Commander to inspect keys and also tried checking the keys from CLI inside the container.

    tasks.py

    from celery import Celery
    from time import sleep

    app = Celery("tasks", broker="redis://localhost:6379", backend="redis://localhost:6379")
    app.conf.result_expires = 3600 # 1 hour result retention

    @app.task
    def process(x, y):
    for _ in range(5):
    sleep(10)
    print("Processing")
    return x**2 + y**2


    docker-compose.yml

    services:
    redis:
    image: redis
    ports:
    - "6379:6379"
    redis-commander:
    image: rediscommander/redis-commander
    ports:
    - "8081:8081"
    environment:
    - REDIS_HOSTS=local:redis:6379


    How I run celery worker

    celery -A tasks worker --loglevel=info -E

    Result of the worker

    -------------- celery@Parvizs-MacBook-Air.local v5.5.3 (immunity)
    --- ***** -----
    -- ******* ---- macOS-14.6.1-arm64-arm-64bit-Mach-O 2025-07-23
    - *** --- * ---
    - ** ---------- [config]
    - ** ---------- .> app: tasks:0x10305c830
    - ** ---------- .> transport: redis://localhost:6379//
    - ** ---------- .> results: redis://localhost:6379/
    - *** --- * --- .> concurrency: 8 (prefork)
    -- ******* ---- .> task events: ON
    --- ***** -----
    -------------- [queues]
    .> celery exchange=celery(direct) key=celery


    Running the task in shell


    process.delay(12, 12)


    Celery logs

    Task tasks.process[89899d0a-cb18-4ed7-8d9c-e8a442e9eb21] received
    Processing
    Processing
    Processing
    Processing
    Processing
    Task tasks.process[89899d0a-cb18-4ed7-8d9c-e8a442e9eb21] succeeded in 50.07s: 288


    Can retrieve tasks from shell like this

    result = process.AsyncResult("89899d0a-cb18-4ed7-8d9c-e8a442e9eb21")
    result.get() # returns 288


    And here is how I check my keys inside the redis container

    docker exec -it <container_id> redis-cli
    127.0.0.1:6379> SELECT 0
    127.0.0.1:6379> KEYS *
    (empty list)


    I have checked databases from 0 to 15, the result is the same.

    Is redis working properly ? If so, why am I not able to see the celery keys.

    Continue reading...

Compartilhe esta Página