折腾:
期间,去用了代码:
<code># celery_task.py from celery import Celery # app = Celery('tasks', broker='redis://localhost//') app = Celery('tasks', broker='redis://localhost') @app.task() def add(x, y): return x + y </code>
保存为celery_task.py
然后去运行,结果出错:
<code>➜ server celery -A celery_task worker [email protected] v4.1.0 (latentcall) Darwin-17.5.0-x86_64-i386-64bit 2018-05-11 17:34:53 [config] .> app: tasks:0x103e1bef0 .> transport: redis://localhost:6379// .> results: disabled:// .> concurrency: 4 (prefork) .> task events: OFF (enable -E to monitor tasks in this worker) [queues] .> celery exchange=celery(direct) key=celery [2018-05-11 17:34:53,255: ERROR/MainProcess] consumer: Cannot connect to redis://localhost:6379//: Error 61 connecting to localhost:6379. Connection refused.. Trying again in 2.00 seconds... </code>
估计是本地Mac中没有运行redis?
celery Error 61 connecting to localhost:6379. Connection refused
Django development server showing Error 61 Connection Refused with Redis – Stack Overflow
<code>➜ server redis-cli zsh: command not found: redis-cli </code>
Error 61 connecting to localhost:6379. Connection refused. · Issue #6 · jart/redisbayes
<code>➜ server redis-server zsh: command not found: redis-server </code>
然后再回去运行celery试试
就正常,没有错误了:
<code>➜ server celery -A celery_task worker [email protected] v4.1.0 (latentcall) Darwin-17.5.0-x86_64-i386-64bit 2018-05-11 17:50:29 [config] .> app: tasks:0x108100ef0 .> transport: redis://localhost:6379// .> results: disabled:// .> concurrency: 4 (prefork) .> task events: OFF (enable -E to monitor tasks in this worker) [queues] .> celery exchange=celery(direct) key=celery </code>
【总结】
此处Celery中,broker设置的是redis,运行celery出错:
consumer Cannot connect to redis Error 61
原因是:
redis(服务)没有运行
解决办法:
去安装和运行redis服务即可。
比如:
转载请注明:在路上 » 【已解决】运行Celery出错:consumer Cannot connect to redis Error 61