17

I've added the Redistogo nano add-on on Heroku and I've tested it out in the console successfully. However when my app tries to connect with Redis I get the following error:

Heroku Log file:

2011-10-12T08:19:50+00:00 app[web.1]: Errno::ECONNREFUSED (Connection refused - Unable to connect to Redis on 127.0.0.1:6379):
2011-10-12T08:19:50+00:00 app[web.1]:   app/controllers/sessions_controller.rb:14:in `create'

Why is it trying to access Redis on localhost?

My Redis.rb in the config/initializers folder has this, which is almost certainly the problem.

#What's pasted below is pasted ad verbatim. I don't know what to change the values to.

uri = URI.parse(ENV["REDISTOGO_URL"])
REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
Simpleton
  • 6,285
  • 11
  • 53
  • 87

2 Answers2

21

Are you using Resque? If so, you'll need to tell Resque which Redis to use.

Resque.redis = REDIS

If not, then the code you've posted about is NOT setting your REDIS connection up.

Neil Middleton
  • 22,105
  • 18
  • 80
  • 134
  • 1
    BTW, you can add this line either at the end of the initializer file shown in the question, or you can just replace the ```REDIS``` variable with ```Resque.redis``` in the initializer for things to work. – fholgado Apr 24 '12 at 18:05
  • 1
    mega thumbs up. this was the solution to my problem. its weird because i used ENV["REDISTOGO_URL"] not ENV["my_actual_url_from_heroku"] and it worked in heroku – Sasha May 19 '12 at 09:06
6

Try this:

heroku config --long | grep REDIS

to see what your REDISTOGO_URL is. You might have set it accidentally.

Jonathan
  • 94
  • 2
  • 2
    Try letting the Redis gem deal with your URL: `Redis.connect(:url => ENV['REDISTOGO_URL'])` – Jonathan Oct 13 '11 at 22:28
  • thank you. your line gave me the inspiration to...not explicitly write something in ENV["REDISTOGO_URL"] – Sasha May 19 '12 at 09:07