Connection refused for Redis on Heroku

2019-07-31 18:35发布

问题:

I'm trying to set up Redis on Heroku as a backend for Celery. I have it working locally but on Heroku, I get this error (after the celery task completes): ConnectionError: Error 111 connecting localhost:6379. Connection refused.

From what I can tell from other answers, that would indicate that the redis server isn't online, though the REDISTOGO_URL seems to be configured properly.

In settings.py:

REDIS_URL = os.getenv('REDISTOGO_URL', 'redis://localhost:6379/0')

In tasks.py:

from celery import Celery
celery = Celery('tasks', backend=settings.CELERY_RESULT_BACKEND, broker=settings.REDIS_URL)

Versions:

celery==3.0.5
celery-with-redis==3.0
django-celery==3.0.4
kombu==2.3.2
redis==2.6.0

回答1:

Looks like you're not using REDISTOGO_URL, since the error message states localhost

Try to check:

  1. heroku config, just to check that REDISTOGO_URL is set in config
  2. Go to shell on heroku (like this) and see if python gets url correctly

Do you run celery on the same app, if not check that other server's config.



回答2:

Found the problem. I had the celery backend configured to the string 'redis' rather than the REDIS_URL.

What I had:

CELERY_RESULT_BACKEND = 'redis'

What it should be:

CELERY_RESULT_BACKEND = REDIS_URL

Dmitry - appreciate your help.