Class: Redis::Pool

Inherits:
Redis
  • Object
show all
Defined in:
lib/redis/pool.rb

Constant Summary collapse

VERSION =
"0.1.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Pool

Returns a new instance of Pool.



9
10
11
12
13
14
# File 'lib/redis/pool.rb', line 9

def initialize(options = {})
  @pool = ConnectionPool.new(size: options.delete(:size)) { Redis::Client.new(options) }
  @id = "Redis::Pool::#{object_id}"

  super
end

Instance Attribute Details

#poolObject (readonly)

Returns the value of attribute pool.



7
8
9
# File 'lib/redis/pool.rb', line 7

def pool
  @pool
end

Instance Method Details

#multiObject

Raises:

  • (ArgumentError)


38
39
40
41
# File 'lib/redis/pool.rb', line 38

def multi
  raise ArgumentError, "Redis::Pool#multi can only be called with a block" unless block_given?
  super
end

#pipelinedObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/redis/pool.rb', line 26

def pipelined
  pipeline = Pipeline.new

  _with_client(pipeline) do |client|
    yield(client)
  end

  synchronize do |client|
    client.call_pipeline(pipeline)
  end
end

#synchronizeObject



16
17
18
19
20
21
22
23
24
# File 'lib/redis/pool.rb', line 16

def synchronize
  if current = Thread.current[@id]
    yield(current)
  else
    @pool.with do |client|
      _with_client(client) { yield(client) }
    end
  end
end