Sidekiq : Redis : Namespace

You need to add the gem ‘redis-namespace’ to namespace the redis keys via sidekiq

From the command line:

$ gem install redis-namespace

Or in your Gemfile:

gem 'redis-namespace'

When you might need this?

If you have multiple server environment or multiple applications hosted using the same redis server then you must namespace your data. Otherwise sidekiq will try to execute tasks from one application with another application’s codebase.

Caveats

Redis::Namespace provides a namespaced interface to Redis by keeping an internal registry of the method signatures in Redis provided by the redis-rb gem; we keep track of which arguments need the namespace added, and which return values need the namespace removed.

and in config/initializers/sidekiq.rb

uri = ENV["REDISTOGO_URL"] || "redis://localhost:6379/0"
app_name = File.basename(Rails.root.to_s)

Sidekiq.configure_server do |config|
 config.redis = { url: uri, namespace: "#{app_name}_#{Rails.env}" }
end

Sidekiq.configure_client do |config|
 config.redis = { url: uri, namespace: "#{app_name}_#{Rails.env}" }
end

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s