Set up Redis + Sidekiq in production

I am trying to configure Redis + Sidekiq in a Passenger / Rails workspace and run into some confusion.

There are several applications on the server with a small number of applications. I am sure that more than one of these applications will use the delayed processing offered by Sidekiq.

My first thought was to use a namespace in Sidekiq to create a namespace for each Rails application.

But then I noticed the databases 16 parameter databases 16 in redis.conf , and I wonder what exactly is happening. I can not find the documentation on it, except for comments in the config:

 # Set the number of databases. The default database is DB 0, you can select # a different one on a per-connection basis using SELECT <dbid> where # dbid is a number between 0 and 'databases'-1 databases 16 

So, I wonder if a standard / example of 16 'databases' means that I could use DB0 for one application and DB1 for another application?!? I do not think this assumption is true, but I can not find more information than:

Redis Cluster does not support multiple databases, such as the standalone version of Redis, there is only database 0, and SELECT is not allowed.

I hope someone can advise me how to share Sidekiq and Redis among the various Rails applications running on the same server.

+4
source share
3 answers

You can use multiple Redis databases; each of which is associated with a Rails application on the same machine. You can put the sidekiq.rb file in initializers with the following code:

 app_name = Rails.application.class.parent_name app_num = case app_name when 'AppOne' 0 when 'AppTwo' 1 when 'AppOne' 2 end Redis.new(db: app_num) # existing DB is selected if already present Sidekiq.configure_server do |config| config.redis = { url: "redis://localhost:6379/#{app_num}", namespace: "#{app_name}" } end Sidekiq.configure_client do |config| config.redis = { url: "redis://localhost:6379/#{app_num}", namespace: "#{app_name}" } end 

This way you allocate Redis DBs as well as namespaces to Sidekiq processes.

+5
source

I think you are looking for namespaces. You can configure the server / client configuration using sidekiq to use different namespaces and configure Passenger / Unicorn to use a different namespace. I did this with Unicorn, but there should be an equivalent option in Passenger.

You can find documentation on how to do this here .

+2
source

database 16 in redis.conf just sets the maximum number of databases. The Redis instance has (0-15). You can change it if you want. I am using Redis DB0 to cache Rails and DB1 for Sidekiq (in addition to using namespaces). Just makes it cleaner if I need FLUSHDB.

In your case, I would use separate Redis DBs for individual applications. If necessary, just increase the number of databases.

0
source

All Articles