最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】运行Celery出错:consumer Cannot connect to redis Error 61

celery crifan 4084浏览 0评论

折腾:

【已解决】Mac本地用Celery实现延时执行任务

期间,去用了代码:

<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]
.&gt; app:         tasks:0x103e1bef0
.&gt; transport:   redis://localhost:6379//
.&gt; results:     disabled://
.&gt; concurrency: 4 (prefork)
.&gt; task events: OFF (enable -E to monitor tasks in this worker)

[queues]
.&gt; 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>

Redis Quick Start – Redis

Error 61 connecting to localhost:6379. Connection refused. · Issue #6 · jart/redisbayes

<code>➜  server redis-server
zsh: command not found: redis-server
</code>

【已解决】Mac中安装和运行redis

然后再回去运行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]
.&gt; app:         tasks:0x108100ef0
.&gt; transport:   redis://localhost:6379//
.&gt; results:     disabled://
.&gt; concurrency: 4 (prefork)
.&gt; task events: OFF (enable -E to monitor tasks in this worker)

[queues]
.&gt; celery           exchange=celery(direct) key=celery
</code>

【总结】

此处Celery中,broker设置的是redis,运行celery出错:

consumer Cannot connect to redis Error 61

原因是:

redis(服务)没有运行

解决办法:

去安装和运行redis服务即可。

比如:

【已解决】Mac中安装和运行redis

转载请注明:在路上 » 【已解决】运行Celery出错:consumer Cannot connect to redis Error 61

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.406 seconds, using 22.11MB memory