Home Articles

字符串而不是Heroku上的redis_url的urlparse.ParseResult(Django)

Asked
Viewed 302 times
1

非常感谢任何有经验将redis配置为heroku上的芹菜代理django项目后端的人的意见 . 我的任务调度在localhost中运行良好,但我发现将它部署在heroku上真的很令人沮丧:

  • 目前我正在运行3个dynos,1个web,1个调度程序和1个worker

  • 我在我的项目中添加了redistogo插件 . Redistogo设置为免费的纳米计划,它给了我10个连接,1个DB和5MB大小的实例

  • 我按照redistogo文档(https://devcenter.heroku.com/articles/redistogo#install-redis-in-python)配置settings.py,或者也尝试实现解决方案的变体here . 都不适合我 . 这是我在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?

我的procfile:

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

2 Answers

  • 0

    看起来像 os.environ.get 正在返回一个字符串(或 str ?不熟悉python),你期望它更像是一个URI对象或什么的 . 普通的python字符串是否会响应 hostname 等方法?

    The documentation也有这一步:

    redis = redis.from_url(redis_url)

    哪个according to these docs将字符串解析为redis对象 .

  • 0

    我对我的解决方案并不满意,但我对我的redistogo主机名,端口和密码进行了硬编码,现在一切运行顺利 .

Related