Class: Bushpig::RedisPool
- Inherits:
-
Object
- Object
- Bushpig::RedisPool
- Defined in:
- lib/bushpig/redis_pool.rb
Instance Method Summary collapse
-
#initialize(size: 1, timeout: 5, redis_options: {}) ⇒ RedisPool
constructor
A new instance of RedisPool.
- #with(options = {}, &block) ⇒ Object
Constructor Details
#initialize(size: 1, timeout: 5, redis_options: {}) ⇒ RedisPool
Returns a new instance of RedisPool.
8 9 10 11 12 13 14 |
# File 'lib/bushpig/redis_pool.rb', line 8 def initialize(size: 1, timeout: 5, redis_options: {}) @size = size @timeout = timeout @redis_options = @pool = ConnectionPool.new(size: @size, timeout: @timeout) { Redis.new(@redis_options) } end |
Instance Method Details
#with(options = {}, &block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/bushpig/redis_pool.rb', line 16 def with( = {}, &block) raise ArgumentError, 'requires a block' unless block_given? retries = 1 begin @pool.with(, &block) rescue Redis::TimeoutError if retries > 0 retries -= 1 retry end raise end end |