Skip to content

Instantly share code, notes, and snippets.

@xxx
Created January 28, 2013 22:41
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save xxx/4659986 to your computer and use it in GitHub Desktop.
Save xxx/4659986 to your computer and use it in GitHub Desktop.
initialization of sidekiq, the hard way
defaults:
:port: 6379
:host: localhost
development:
:db: 2
:namespace: development
# force use of Redis::Distributed
:host:
- localhost
datastore_config = YAML.load(ERB.new(File.read(File.join(Rails.root, "config", "redis.yml"))).result)
datastore_config = datastore_config["defaults"].merge(datastore_config[::Rails.env])
if datastore_config[:host].is_a?(Array)
if datastore_config[:host].length == 1
datastore_config[:host] = datastore_config[:host].first
else
datastore_config = datastore_config[:host].map do |host|
host_has_port = host =~ /:\d+\z/
if host_has_port
"redis://#{host}/#{datastore_config[:db] || 0}"
else
"redis://#{host}:#{datastore_config[:port] || 6379}/#{datastore_config[:db] || 0}"
end
end
end
end
Sidekiq.configure_server do |config|
config.redis = ::ConnectionPool.new(:size => Sidekiq.options[:concurrency] + 2, :timeout => 2) do
redis = if datastore_config.is_a? Array
Redis::Distributed.new(datastore_config)
else
Redis.new(datastore_config)
end
Redis::Namespace.new('resque', :redis => redis)
end
end
@saipraveen-a
Copy link

Can you please explain what is the significance of line 29?

@saipraveen-a
Copy link

With this configuration, if i have configured a CONCURRENCY setting of 5, I will have 7 workers running? How many of these are going to process jobs from Server1 vs Server2? Is there a way of controlling that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment