mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Use redis' default driver (#3956)
Redis stores its loaded drivers in `Redis::Connection.drivers` and uses the last one of them when initializing a new client. Sidekiq always uses `'ruby'` (or `Redis::Connection::Ruby`) per default, though. With this commit we are following redis' default by passing the last loaded driver per default (or a given `:driver`).
This commit is contained in:
parent
78344b6710
commit
da3fbed14b
2 changed files with 32 additions and 1 deletions
|
@ -78,7 +78,7 @@ module Sidekiq
|
||||||
opts.delete(:network_timeout)
|
opts.delete(:network_timeout)
|
||||||
end
|
end
|
||||||
|
|
||||||
opts[:driver] ||= 'ruby'
|
opts[:driver] ||= Redis::Connection.drivers.last || 'ruby'
|
||||||
|
|
||||||
# Issue #3303, redis-rb will silently retry an operation.
|
# Issue #3303, redis-rb will silently retry an operation.
|
||||||
# This can lead to duplicate jobs if Sidekiq::Client's LPUSH
|
# This can lead to duplicate jobs if Sidekiq::Client's LPUSH
|
||||||
|
|
|
@ -144,6 +144,37 @@ class TestRedisConnection < Sidekiq::Test
|
||||||
assert_equal 1, pool.instance_eval{ @timeout }
|
assert_equal 1, pool.instance_eval{ @timeout }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "driver" do
|
||||||
|
it "uses redis' ruby driver" do
|
||||||
|
pool = Sidekiq::RedisConnection.create
|
||||||
|
redis = pool.checkout
|
||||||
|
|
||||||
|
assert_equal Redis::Connection::Ruby, redis.instance_variable_get(:@client).driver
|
||||||
|
end
|
||||||
|
|
||||||
|
it "uses redis' default driver if there are many available" do
|
||||||
|
begin
|
||||||
|
redis_driver = Object.new
|
||||||
|
Redis::Connection.drivers << redis_driver
|
||||||
|
|
||||||
|
pool = Sidekiq::RedisConnection.create
|
||||||
|
redis = pool.checkout
|
||||||
|
|
||||||
|
assert_equal redis_driver, redis.instance_variable_get(:@client).driver
|
||||||
|
ensure
|
||||||
|
Redis::Connection.drivers.pop
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "uses a given :driver" do
|
||||||
|
redis_driver = Object.new
|
||||||
|
pool = Sidekiq::RedisConnection.create(:driver => redis_driver)
|
||||||
|
redis = pool.checkout
|
||||||
|
|
||||||
|
assert_equal redis_driver, redis.instance_variable_get(:@client).driver
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".determine_redis_provider" do
|
describe ".determine_redis_provider" do
|
||||||
|
|
Loading…
Reference in a new issue