Class: Redis::Pool

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

Constant Summary collapse

VERSION =
"0.1.0"

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)


34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/redis/pool.rb', line 34

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

  pipeline = Pipeline::Multi.new

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

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

#pipelinedObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/redis/pool.rb', line 22

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
# File 'lib/redis/pool.rb', line 16

def synchronize
  @pool.with do |client|
    _with_client(client) { yield(client) }
  end
end