7

I'm trying to understand the Redis & Sidekiq configuration in a Passenger+Rails app and have run into some lack of understanding. I start the redis server independently of my rails app, while Sidekiq is a gem in my Rails app. I start it likewise: (no sidekiq.yml file needed for me)

bundle exec sidekiq

Following is my sidekiq.rb initializer:

require 'sidekiq'
require 'sidekiq-status'

Sidekiq.configure_client do |config|
  config.client_middleware do |chain|
    chain.add Sidekiq::Status::ClientMiddleware
  end
end

Sidekiq.configure_server do |config|
  config.server_middleware do |chain|
    chain.add Sidekiq::Status::ServerMiddleware, expiration: 30.minutes
  end
  config.client_middleware do |chain|
    chain.add Sidekiq::Status::ClientMiddleware
  end
end

I went through some library classes, but to no avail.

I want to understand where does Sidekiq configure it's Redis server details. It defaults to localhost:6379, but I am not quite sure how.
Also, if I wish to use Memcached in future, how can I change that?

Sid
  • 4,893
  • 14
  • 55
  • 110

2 Answers2

11

From sidekiq docs:

By default, Sidekiq tries to connect to Redis at localhost:6379

https://github.com/mperham/sidekiq/wiki/Using-Redis

You can change the port in the initializer:

 Sidekiq.configure_server do |config|
      config.redis = { url: 'redis://redis.example.com:7372/12' }
 end

From the looks of it sidekiq works only with redis

Sidekiq uses Redis to store all of its job and operational data.

Joel Blum
  • 7,750
  • 10
  • 41
  • 60
  • Oh, I seemed to have missed that. Thanks @Joel_Blum – Sid Feb 07 '17 at 07:46
  • what does the `/12` correspond to? In the examples on the site now it seems to indicate you should use `/0` as the postfix but I still don't understand what it stands for? – Batkins Oct 29 '21 at 23:16
  • the database number https://www.mikeperham.com/2015/09/24/storing-data-with-redis/#:~:text=Databases,more%20databases%2C%20look%20in%20redis. – Joel Blum Oct 31 '21 at 18:57
1

Here is what I did from the other answer:

# frozen_string_literal: true
Sidekiq.configure_server do |config|
  config.redis = {
    url: ENV.fetch("SIDEKIQ_REDIS_URL", "redis://localhost:6379/1")
  }
end
Dorian
  • 7,749
  • 4
  • 38
  • 57