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.
/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.after_initialize do
PasswordAgingJob.perform_later
SetOffCallJob.perform_later
end
uri = URI.parse(ENV["REDISTOGO_URL"] || "redis://localhost:6379/" )
REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
ActiveJob::Base.queue_adapter = :sidekiq
Heroku Data for Redis is an in-memory key-value data store, run by Heroku, that is provisioned and managed as an add-on. Heroku Data for Redis is accessible from any language with a Redis driver, including all languages and frameworks supported by Heroku.
Reliable and powerful Redis as a service. Starting at $0/mo.
By default, redis-cli connects to the server at the address 127.0. 0.1 with port 6379.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With