You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Channels与Celery集成报错:Redis连接被拒绝(Errno 10061)求助

Troubleshooting ConnectionRefusedError with Celery & Redis

Hey there, let's break down this issue step by step—your ConnectionRefusedError: [Errno 10061] Connect call failed ('::1', 6379) is pointing to a problem between Celery and Redis (the broker Celery uses to manage tasks). Here's how to resolve it:

1. First, Confirm Redis is Running

This is the most common cause of the error—if Redis isn't active, Celery can't connect to it.

  • Windows: Open a command prompt and run redis-server.exe (make sure Redis is installed and added to your PATH, or execute it directly from its installation folder).
  • Linux/macOS: Use sudo systemctl start redis to launch the service, or run redis-server directly in a terminal.
  • To verify it's working, run redis-cli ping—you should get a PONG response back.

2. Check Your Celery Broker Configuration

Make sure your Django settings have the correct Redis connection details. In settings.py, look for these lines:

CELERY_BROKER_URL = 'redis://127.0.0.1:6379/0'  # Use 127.0.0.1 instead of ::1 to avoid IPv6 issues
CELERY_RESULT_BACKEND = 'redis://127.0.0.1:6379/0'
  • Double-check the port (6379 is Redis's default) and host. If localhost isn't working, try 127.0.0.1 to bypass IPv6 conflicts.
  • If Redis is password-protected, update the URL to include it: redis://:your_password_here@127.0.0.1:6379/0.

3. Ensure Your Celery Worker is Running

Even if Redis is up, Celery can't process tasks unless its worker is active. From your project root directory, run:

celery -A your_project_name worker --loglevel=info

Replace your_project_name with the name of your Django project (the folder containing settings.py). You should see logs confirming the worker connected to Redis successfully.

4. Check Firewall Settings

A local firewall might be blocking connections to port 6379:

  • Windows: Open Windows Defender Firewall → "Allow an app through firewall" and ensure Redis and your Celery worker are permitted.
  • Linux: Run sudo ufw allow 6379 to open the port for local connections.

5. Validate the Task Call in Your Async Consumer

Since you're using an AsyncWebsocketConsumer, make sure you're calling your Celery task correctly. Celery's delay() method is non-blocking, but if you run into event loop issues, wrap it with async_to_sync:

from asgiref.sync import async_to_sync
from .tasks import MensajeAlGrupo

# Inside your consumer's receive method
async_to_sync(MensajeAlGrupo.delay)(your_message_args)

6. Test the Task Directly

To rule out issues with your consumer, test the Celery task from the Django shell:

from your_app_name.tasks import MensajeAlGrupo
MensajeAlGrupo.delay("test_hola_message")

If this throws the same connection error, the problem is definitely with your Redis/Celery setup, not the consumer logic.

Once you fix the Redis connection issue, your task should trigger correctly when the "hola" message is sent, and the state should update as expected.

内容的提问来源于stack exchange,提问作者user9548476

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 06:29:40