Class: Bushpig::RedisPool

Inherits:
Object
  • Object
show all
Defined in:
lib/bushpig/redis_pool.rb

Instance Method Summary collapse

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 = redis_options

  @pool = ConnectionPool.new(size: @size, timeout: @timeout) { Redis.new(@redis_options) }
end

Instance Method Details

#with(options = {}, &block) ⇒ Object

Raises:

  • (ArgumentError)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/bushpig/redis_pool.rb', line 16

def with(options = {}, &block)
  raise ArgumentError, 'requires a block' unless block_given?

  retries = 1
  begin
    @pool.with(options, &block)
  rescue Redis::TimeoutError
    if retries > 0
      retries -= 1
      retry
    end
    raise
  end
end