Haseeb Ahmad
Haseeb Ahmad

Reputation: 8730

Sidekiq Redis::CannotConnectError: Error connecting to Redis on 127.0.0.1:6379 on production

config/initializers/sidekiq.rb

Sidekiq.configure_server do |config|
   config.redis = { :url => 'redis://192.xxx.xxx.xx:6379/0' }
end

In production console when I do

ActivationWorker.perform_async(877459)

It gives an error

Redis::CannotConnectError: Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED)

Even sidekiq.log prints

Booting Sidekiq 5.1.3 with redis options {:url=>"redis://192.xxx.xxx.xx:6379/0", :id=>"Sidekiq-server-PID-646"}

Upvotes: 3

Views: 5565

Answers (2)

Roc Khalil
Roc Khalil

Reputation: 1385

Based on the comments, we know that Redis is on a separate server.

Rails Server

Create a file in initializers: config/initializers/sidekiq.rb:

Sidekiq.configure_server do |config|
  config.redis = {
    url: "redis://192.xxx.xxx.xxx:6379/12"
  }
end

Sidekiq.configure_client do |config|
  config.redis = {
    url: "redis://192.xxx.xxx.xxx:6379/12"
  }
end

Redis server

  • Edit /etc/redis/redis.conf
  • Update your binded port
  • example: bind 192.xxx.xxx.xxx
  • restart redis

Upvotes: 0

Martin
Martin

Reputation: 4222

It is important to note that to configure the location of Redis, you must define both the Sidekiq.configure_server and Sidekiq.configure_client blocks

Straight from the docs

So also add to your config/initializers/sidekiq.rb:

Sidekiq.configure_client do |config|
   config.redis = { :url => 'redis://192.xxx.xxx.xx:6379/0' }
end

Also important notes from docs:

NOTE: The configuration hash must have symbolized keys.

NOTE: Unknown parameters are passed to the underlying Redis client so any parameters supported by the driver can go in the Hash.

Upvotes: 2

Related Questions