Skip to content

Instantly share code, notes, and snippets.

@tareksamni
Last active August 29, 2015 14:00
Show Gist options
  • Save tareksamni/03325d7ac950c8872897 to your computer and use it in GitHub Desktop.
Save tareksamni/03325d7ac950c8872897 to your computer and use it in GitHub Desktop.
Sidekiq Initializer base on current active environment
## For more details refer to: http://tsamni.com/post/84515089035/sidekiq-performing-background-or-delayed-jobs-with
# config/redis.yml
# Redis db configuration file
# development environment
development:
host: 'localhost'
port: '6379'
# local testing environment
test:
host: 'localhost'
port: '6379'
# production environment
production:
host: 'your.aws.elastic.cache.instance.endpoint.cache.amazonaws.com'
port: '6379'
## For more details refer to: http://tsamni.com/post/84515089035/sidekiq-performing-background-or-delayed-jobs-with
# config/initializers/sidekiq.rb
rails_root = Rails.root || File.dirname(__FILE__) + '/../..'
rails_env = Rails.env || 'development'
redis_config = YAML.load_file(rails_root.to_s + '/config/redis.yml')
redis_config.merge! redis_config.fetch(Rails.env, {})
redis_config.symbolize_keys!
Sidekiq.configure_server do |config|
config.redis = { :url => "redis://#{redis_config[:host]}:#{redis_config[:port]}/12", :namespace => 'Sidekiq' }
end
Sidekiq.configure_client do |config|
config.redis = { :url => "redis://#{redis_config[:host]}:#{redis_config[:port]}/12", :namespace => 'Sidekiq' }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment