mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Symbolize keys in options hash for RedisConnection.create
Fixes an edge case where a stringified `namespace` key is ignored. A `namespace` key may be a string if the Sidekiq Redis config is loaded from a yml file. Also minor, syntactical improvements to error messaging. Existing tests pass. Added a new test to address this edge-case.
This commit is contained in:
parent
d822c3a850
commit
9d09539eba
2 changed files with 11 additions and 4 deletions
|
@ -8,6 +8,8 @@ module Sidekiq
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
def create(options={})
|
def create(options={})
|
||||||
|
options = options.symbolize_keys
|
||||||
|
|
||||||
options[:url] ||= determine_redis_provider
|
options[:url] ||= determine_redis_provider
|
||||||
|
|
||||||
size = options[:size] || (Sidekiq.server? ? (Sidekiq.options[:concurrency] + 5) : 5)
|
size = options[:size] || (Sidekiq.server? ? (Sidekiq.options[:concurrency] + 5) : 5)
|
||||||
|
@ -33,7 +35,7 @@ module Sidekiq
|
||||||
# - enterprise's leader election
|
# - enterprise's leader election
|
||||||
# - enterprise's cron support
|
# - enterprise's cron support
|
||||||
def verify_sizing(size, concurrency)
|
def verify_sizing(size, concurrency)
|
||||||
raise ArgumentError, "Your Redis connection pool is too small for Sidekiq to work, your pool has #{size} connections but really needs to have at least #{concurrency + 2}" if size <= concurrency
|
raise ArgumentError, "Your Redis connection pool is too small for Sidekiq to work. Your pool has #{size} connections but really needs to have at least #{concurrency + 2}" if size <= concurrency
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_client(options)
|
def build_client(options)
|
||||||
|
@ -45,8 +47,8 @@ module Sidekiq
|
||||||
require 'redis/namespace'
|
require 'redis/namespace'
|
||||||
Redis::Namespace.new(namespace, :redis => client)
|
Redis::Namespace.new(namespace, :redis => client)
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
Sidekiq.logger.error("Your Redis configuration use the namespace '#{namespace}' but the redis-namespace gem not included in Gemfile." \
|
Sidekiq.logger.error("Your Redis configuration uses the namespace '#{namespace}' but the redis-namespace gem is not included in the Gemfile." \
|
||||||
"Add the gem to your Gemfile in case you would like to keep using a namespace, otherwise remove the namespace parameter.")
|
"Add the gem to your Gemfile to continue using a namespace. Otherwise, remove the namespace parameter.")
|
||||||
exit(-127)
|
exit(-127)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
|
@ -27,11 +27,16 @@ class TestRedisConnection < Sidekiq::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "namespace" do
|
describe "namespace" do
|
||||||
it "uses a given :namespace" do
|
it "uses a given :namespace set by a symbol key" do
|
||||||
pool = Sidekiq::RedisConnection.create(:namespace => "xxx")
|
pool = Sidekiq::RedisConnection.create(:namespace => "xxx")
|
||||||
assert_equal "xxx", pool.checkout.namespace
|
assert_equal "xxx", pool.checkout.namespace
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "uses a given :namespace set by a string key" do
|
||||||
|
pool = Sidekiq::RedisConnection.create("namespace" => "xxx")
|
||||||
|
assert_equal "xxx", pool.checkout.namespace
|
||||||
|
end
|
||||||
|
|
||||||
it "uses given :namespace over :namespace from Sidekiq.options" do
|
it "uses given :namespace over :namespace from Sidekiq.options" do
|
||||||
Sidekiq.options[:namespace] = "xxx"
|
Sidekiq.options[:namespace] = "xxx"
|
||||||
pool = Sidekiq::RedisConnection.create(:namespace => "yyy")
|
pool = Sidekiq::RedisConnection.create(:namespace => "yyy")
|
||||||
|
|
Loading…
Reference in a new issue