herokuflaskredisheroku-redis

Flask app not connecting to heroku-redis


I've looked at similar questions asked/answered here, but I can't figure out my issue. My flask app, when deployed on heroku, isn't connecting to my heroku-redis instance. Instead, in my heroku logs, I am getting:

2018-05-10T20:36:12.520794+00:00 heroku[web.1]: Starting process with command `flask db upgrade; flask translate compile; gunicorn microblog:app`
2018-05-10T20:36:12.705812+00:00 heroku[worker.1]: Starting process with command `rq worker microblog-tasks`
2018-05-10T20:36:13.385204+00:00 heroku[worker.1]: State changed from starting to up
2018-05-10T20:36:15.060614+00:00 heroku[worker.1]: Process exited with status 1
2018-05-10T20:36:15.080485+00:00 heroku[worker.1]: State changed from up to crashed
2018-05-10T20:36:14.989923+00:00 app[worker.1]: Error 111 connecting to localhost:6379. Connection refused.

Why is my worker so determined to connect to my local redis server? My procfile is:

web: flask db upgrade; flask translate compile; gunicorn microblog:app
worker: rq worker microblog-tasks

Running "heroku config:get REDIS_URL" shows that the env var REDIS_URL is indeed set in heroku. Do background tasks require more than one dyno? I have no trouble with my app locally, just when deploying on heroku.

Separate but related question: What are the differences between redis, redistogo, and rediscloud? When would one use each of them? Really appreciate any help.


Solution

  • There was actually an omission in my article, I apologize for that.

    The command that starts the RQ worker needs to include the connection URL for Redis:

    worker: rq worker -u $REDIS_URL microblog-tasks