Reputation: 8710
I am trying to cache my requests using requests_cache
and redis like so:
requests_cache.install_cache(
'requests_cache', backend='redis', expire_after=600
)
and when Redis is run on localhost:6379
, everything is fine and works out of the box.
However when I deploy my app to Heroku where there is a REDIS_URL environment variable, the above command fails because obviousle REDIS_URL does not point to localhost
:
Error 111 connecting to localhost:6379. Connection refused.
So the question is, how do I make it work on Heroku? the docs aren't clear on the subject.
Upvotes: 2
Views: 392
Reputation: 3271
You have to pass an additional argument to install_cache
called connection
which will be of StrictRedis
type. So I guess create it like that:
r = redis.StrictRedis(host='REDIS_URL', port=6379, db=0)
requests_cache.install_cache(
'requests_cache', backend='redis', expire_after=600, connection=r
)
Or something similar, depending on how much information REDIS_URL
contains (protocol, port etc.)
Upvotes: 1