deploying redis to heroku unable to connect

19,360

Solution 1

For my setup I have /config/initializers/redis.rb with these lines:

uri = URI.parse(ENV["REDISTOGO_URL"] || "redis://localhost:6379/" )
REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)

My REDISTOGO_URL is defined in my heroku configuration. You should be able to validate that by typing:

heroku config --app my_app

You'll see in the output the value for REDISTOGO_URL

You should copy your REDISTOGO_URL directly from Redis To Go. You find it in by going to the instance in heroku and clicking on Add Ons -> Redis To Go.

Here are a couple pointers:

  1. Verify you have your REDIS_TO_GO URL in your heroku config from the command line like I've demonstrated above.
  2. Verify the REDIS_TO_GO URL is identical to the one assigned to that instance in the Add Ons -> Redis To Go config.

Solution 2

i fixed it. i can't believe it! my complete solution is

uri = URI.parse(ENV["REDISTOGO_URL"])
REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
Resque.redis = REDIS

verbatim. it works without explicitly setting the url because i guess heroku tries to set it up for me already

Solution 3

I got the same thing, so, basically Sidekiq was not grabbing the REDISCLOUD_URL from vars, it was grabbing REDIS_PROVIDER.

heroku config:set REDIS_PROVIDER=REDISCLOUD_URL

It worked like a charm.

Share:
19,360
Sasha
Author by

Sasha

Updated on June 06, 2022

Comments

  • Sasha
    Sasha almost 2 years

    ive been trying to get resque to work with heroku. i can successfully get it to work in development mode, however when i try pushing to heroku i get

    Errno::ECONNREFUSED (Connection refused - Unable to connect to Redis on 127.0.0.1:6379):
    

    i then read and followed http://blog.redistogo.com/2010/07/26/resque-with-redis-to-go/

    i put the configurations listed in the site but got the following error

    SocketError (getaddrinfo: nodename nor servname provided, or not known):
    

    i put in my initializers/resque.rb

    Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }
    
    ENV["redis://redistogo:[email protected]:9254/"] ||= "redis://heroku_username:heroku_password@host:9254/"
    uri = URI.parse(ENV["redis://redistogo:[email protected]:9254/"])
    Resque.redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
    

    however it throws the error mentioned above. on my dev mode now, i get the error as well.

    i tried using my heroku username (im using the add on from heroku), putting my password to heroku, and changing the port to 9254. however i keep getting the socket error now. what am i doing wrong?

    help would be much appreciated. thank you

    UPDATE.

    @kevin

    i tried

    uri = URI.parse(ENV["my_url_string"] || "redis://localhost:9254/" )
    REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
    

    in a initializer/redis.rb as well but i get the following error

    Errno::ECONNREFUSED (Connection refused - Unable to connect to Redis on 127.0.0.1:6379):
    

    are the numbers in the error, ie 127.0.0.1:6379 significant? ive checked my redis gui app and also from heroku config that my port number is 9254

    REDISTOGO_URL       => redis://redistogo:[email protected]:9254/
    

    did you have any other configuration settings? thanks for helping!

    FINAL UPDATE.

    i fixed it. i can't believe it! my complete solution is

    uri = URI.parse(ENV["REDISTOGO_URL"])
    REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
    Resque.redis = REDIS
    

    verbatim. it works without explicitly setting the url because i guess heroku tries to set it up for me already

  • Sasha
    Sasha almost 12 years
    yes ive checked using the command you said above and my url is matching. did you have any other initialization for redis? unfortunately i still get the error Errno::ECONNREFUSED (Connection refused - Unable to connect to Redis on 127.0.0.1:6379):
  • Sasha
    Sasha almost 12 years
    i much appreciate your help = )
  • Rafael Oliveira
    Rafael Oliveira over 10 years
    Remember to add before_fork and after_fork hooks if you are using unicorn. devcenter.heroku.com/articles/rails-unicorn#caveats Also, Redis To Go docs: redistogo.com/documentation/resque
  • courtsimas
    courtsimas about 10 years
    For me, i had to do heroku labs:enable user-env-compile -a myapp to get it to read my ENV vars during deployment.
  • oky_sabeni
    oky_sabeni almost 9 years
    heroku config:set REDIS_PROVIDER=REDISTOGO_URL for me
  • GhostRider
    GhostRider over 8 years
    heroku config:set REDIS_PROVIDER=REDISTOGO_URL worked for me too (Rails 4)
  • d1jhoni1b
    d1jhoni1b almost 8 years
    heroku config:set REDIS_PROVIDER=REDISTOGO_URL worked for as well too (Sinatra)