mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Allow generic Redis providers via env var
Instead of hardcoding every provider's environment variable, Sidekiq now supports both REDIS_PROVIDER and REDIS_URL env vars. Let's say you run on Heroku and you use openredis. You can now set REDIS_PROVIDER=OPENREDIS_URL and Sidekiq will use the openredis uri. If you switch to another provider, all you need to do is reset REDIS_PROVIDER. An example of switching to RedisGreen: REDIS_PROVIDER=REDISGREEN_URL. Easy peasy! Sidekiq also supports using your own url with REDIS_URL. While you can still pass in the URL to Sidekiq::RedisConnection.create, it's also now possible to set it with just an env var. Closes #443
This commit is contained in:
parent
f7b49cabcc
commit
36bb71883a
2 changed files with 16 additions and 1 deletions
|
@ -1,3 +1,8 @@
|
|||
HEAD
|
||||
-----------
|
||||
|
||||
- Allow generic Redis provider as environment variable. [#443]
|
||||
|
||||
2.3.3
|
||||
-----------
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ require 'redis/namespace'
|
|||
module Sidekiq
|
||||
class RedisConnection
|
||||
def self.create(options={})
|
||||
url = options[:url] || ENV['REDISTOGO_URL'] || 'redis://localhost:6379/0'
|
||||
url = options[:url] || determine_redis_provider || 'redis://localhost:6379/0'
|
||||
driver = options[:driver] || 'ruby'
|
||||
# need a connection for Fetcher and Retry
|
||||
size = options[:size] || (Sidekiq.server? ? (Sidekiq.options[:concurrency] + 2) : 5)
|
||||
|
@ -24,5 +24,15 @@ module Sidekiq
|
|||
end
|
||||
end
|
||||
private_class_method :build_client
|
||||
|
||||
def self.determine_redis_provider
|
||||
provider = if ENV.has_key? 'REDISTOGO_URL'
|
||||
'REDISTOGO_URL'
|
||||
else
|
||||
ENV['REDIS_PROVIDER'] || 'REDIS_URL'
|
||||
end
|
||||
ENV[provider]
|
||||
end
|
||||
private_class_method :determine_redis_provider
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue