首页 > 解决方案 > Django Celery Heroku - 更改了 Redis URL 环境变量,现在出现错误

问题描述

我更新了环境变量,在 Heroku 中称为 REDDIS_URL 的配置变量

我关闭了我的应用测功机和我的工人测功机。

然后我重新启动了我的应用程序测功机,web gunicorn myapplication.wsgi没有任何问题

然后我重新启动了我的工作人员worker celery -A myapplication worker -l info --concurrency 2,这导致我在日志中收到以下错误[2021-07-06 16:00:05: ERROR/MainProcess] Cannot connect to redis://NEW_REDDIS_URL//: Error while reading from socket: (104, 'Connection reset by peer').

如何让工作人员为 REDDIS_URL 引用更新的配置变量(环境变量)?

标签: djangoherokurediscelery

解决方案


使用 OS 在 settings.py 中设置你的 redis URL 是一个好习惯os.environ.get('REDIS_URL')

Heroku 会定期轮换凭证并更新附加此数据存储的应用程序。

Heroku 建议使用加密,因此建议使用rediss://URL 而不是redis://

对于芹菜,类似:CELERY_BROKER_URL ='rediss://:{Password}@{Host}:{Port}'

Heroku 命令轻松获取此网址heroku redis:credentials REDIS_URL

参考:https ://devcenter.heroku.com/articles/heroku-redis#using-the-cli


推荐阅读