非常感谢任何有将 redis 配置为 heroku 上 celery-brokered django 项目后端经验的人的意见。我的任务调度在 localhost 上运行良好,但我发现将它部署在 heroku 上真的很令人沮丧:
- 目前我正在运行 3 个 dynos、1 个 web、1 个调度程序和 1 个 worker
- 我将 redistogo 插件添加到我的项目中。Redistogo 设置为免费的 nano 计划,它为我提供 10 个连接、1 个 DB 和一个 5MB 大小的实例
我按照 redistogo 文档 ( https://devcenter.heroku.com/articles/redistogo#install-redis-in-python ) 配置 settings.py ,或者,也尝试在此处实现解决方案的变体。也不为我工作。这是我在 settings.py 中的内容:
redis_url = os.environ.get('REDISTOGO_URL', 'http://localhost:6959') CACHES = { 'default': { 'BACKEND': 'redis_cache.RedisCache',, 'LOCATION': '%s:%s' % (redis_url.hostname, redis_url.port), 'OPTIONS': { 'DB': 0, # or 1? 'PASSWORD': redis_url.password, #'PARSER_CLASS': 'redis.connection.HiredisParser' }, }, } CELERY_RESULT_BACKEND = redis_url BROKER_URL = 'redis://localhost:6959/0'
这是我尝试运行应用程序时的 heroku 日志:
2013-07-11T12:16:10.998516+00:00 app[web.1]: apps = settings.INSTALLED_APPS
2013-07-11T12:16:10.998516+00:00 app[web.1]: mod = importlib.import_module(self.SETTINGS_MODULE)
2013-07-11T12:16:10.998263+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
2013-07-11T12:16:10.998263+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 263, in fetch_command
2013-07-11T12:16:10.998516+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__
2013-07-11T12:16:10.998516+00:00 app[web.1]: self._setup(name)
2013-07-11T12:16:10.998516+00:00 app[web.1]: self._wrapped = Settings(settings_module)
2013-07-11T12:16:10.998516+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 132, in __init__
2013-07-11T12:16:10.998516+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
2013-07-11T12:16:10.998516+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in _setup
2013-07-11T12:16:10.998712+00:00 app[web.1]: 'LOCATION': '%s:%s' % (redis_url.hostname, redis_url.port),
2013-07-11T12:16:10.998712+00:00 app[web.1]: AttributeError: 'str' object has no attribute 'hostname'
2013-07-11T12:16:12.201202+00:00 heroku[web.1]: Process exited with status 1
2013-07-11T12:16:12.250743+00:00 heroku[web.1]: State changed from starting to crashed
如何将 redis_url 视为 URI 而不是 str?
我的过程文件:
web: python manage.py run_gunicorn -b 0.0.0.0:$PORT -w 3 --log-level info
scheduler: python manage.py celeryd -B -E
worker: python manage.py celeryd -E -B --loglevel=INFO
在要求中我有 django-redis-cache==0.10.0, redis==2.7.6, django-celery==3.0.17, celery celery==3.0.20 和 kombu==2.5.12