Permalink
Browse files

Allow setting of a custom timeout for the Redis Connection Pool

  • Loading branch information...
1 parent ddd4cab commit 5a4de159f0e1f457bdb90d4f2a8552623fa9b6a0 @LeakyBucket LeakyBucket committed Jul 16, 2013
Showing with 18 additions and 1 deletion.
  1. +2 −0 .gitignore
  2. +2 −1 lib/sidekiq/redis_connection.rb
  3. +14 −0 test/test_redis_connection.rb
View
@@ -6,4 +6,6 @@ Gemfile.lock
dump.rdb
.rbx
coverage/
+vendor/
+.bundle/
.sass-cache/
@@ -9,10 +9,11 @@ def create(options={})
url = options[:url] || determine_redis_provider || 'redis://localhost:6379/0'
# need a connection for Fetcher and Retry
size = options[:size] || (Sidekiq.server? ? (Sidekiq.options[:concurrency] + 2) : 5)
+ timeout = options[:timeout] || 1
log_info(url, options)
- ConnectionPool.new(:timeout => 1, :size => size) do
+ ConnectionPool.new(:timeout => timeout, :size => size) do
build_client(url, options[:namespace], options[:driver] || 'ruby')
end
end
@@ -22,6 +22,20 @@ class TestRedisConnection < Minitest::Test
assert_equal "yyy", pool.checkout.namespace
end
end
+
+ describe "timeout" do
+ it "uses a given :timeout over the default of 1" do
+ pool = Sidekiq::RedisConnection.create(:timeout => 5)
+
+ assert_equal 5, pool.instance_eval{ @timeout }
+ end
+
+ it "uses the default timeout of 1 if no override" do
+ pool = Sidekiq::RedisConnection.create
+
+ assert_equal 1, pool.instance_eval{ @timeout }
+ end
+ end
end
describe ".determine_redis_provider" do

0 comments on commit 5a4de15

Please sign in to comment.