1
0
Fork 0
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:
Christopher Louvet 2016-05-26 12:50:37 +07:00
parent d822c3a850
commit 9d09539eba
2 changed files with 11 additions and 4 deletions

View file

@ -8,6 +8,8 @@ module Sidekiq
class << self
def create(options={})
options = options.symbolize_keys
options[:url] ||= determine_redis_provider
size = options[:size] || (Sidekiq.server? ? (Sidekiq.options[:concurrency] + 5) : 5)
@ -33,7 +35,7 @@ module Sidekiq
# - enterprise's leader election
# - enterprise's cron support
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
def build_client(options)
@ -45,8 +47,8 @@ module Sidekiq
require 'redis/namespace'
Redis::Namespace.new(namespace, :redis => client)
rescue LoadError
Sidekiq.logger.error("Your Redis configuration use the namespace '#{namespace}' but the redis-namespace gem not included in Gemfile." \
"Add the gem to your Gemfile in case you would like to keep using a namespace, otherwise remove the namespace parameter.")
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 to continue using a namespace. Otherwise, remove the namespace parameter.")
exit(-127)
end
else

View file

@ -27,11 +27,16 @@ class TestRedisConnection < Sidekiq::Test
end
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")
assert_equal "xxx", pool.checkout.namespace
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
Sidekiq.options[:namespace] = "xxx"
pool = Sidekiq::RedisConnection.create(:namespace => "yyy")