16

I'm using sidekiq with active_job in my rails application. The job currently works but I am unable to get connect to the Redis when deploying to heroku. In heroku I have the RedisToGo addon. When pushing to heroku I get the following error.

error

/app/vendor/bundle/ruby/2.2.0/gems/redis-3.2.1/lib/redis/client.rb:331:in `rescue in establish_connection': Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED) (Redis::CannotConnectError)

config/application.rb

config.after_initialize do
  PasswordAgingJob.perform_later
  SetOffCallJob.perform_later
end

config/initializers/redis.rb

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

config/initializers/active_job.rb

ActiveJob::Base.queue_adapter = :sidekiq
Antarr Byrd
  • 24,863
  • 33
  • 100
  • 188

4 Answers4

25

Set REDIS_PROVIDER to the name of the env var with your Redis URL.

Type this: heroku config:set REDIS_PROVIDER=REDISTOGO_URL. Restart.

Explained here: https://github.com/mperham/sidekiq/wiki/Using-Redis#using-an-env-variable

Mike Perham
  • 21,300
  • 6
  • 59
  • 61
  • I have a feeling a few people land here when they also don't have the right worker set up. Mike, do you happen to know how one configures their heroku app such that a worker is ready to go to run Redis? – karns Jan 22 '20 at 15:22
3

Setting REDIS_URL in heroku config help me to resolve:

Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED) (Redis::CannotConnectError)
Roman Kiselenko
  • 43,210
  • 9
  • 91
  • 103
  • I spent weeks trying to figure this out, tried all kind of solution, but it was that simple! THANK YOU! – Rene Chan Apr 19 '19 at 06:38
2

You must set the REDISTOGO_URL on Heroku.

Click on Settings, and then Reveal Config Vars.

B Seven
  • 44,484
  • 66
  • 240
  • 385
0

Setting REDIS_URL to redis://@pike.redistogo.com:10731/ seem to work for me.

Prabin Deka
  • 301
  • 3
  • 7