Class: Redis::EM::ConnectionPool
- Inherits:
-
Object
- Object
- Redis::EM::ConnectionPool
show all
- Defined in:
- lib/redis/em-connection-pool.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ConnectionPool.
5
6
7
8
9
10
11
|
# File 'lib/redis/em-connection-pool.rb', line 5
def initialize(opts)
@pool = []
@queue = []
@acquired = {}
opts[:size].times { @pool << yield }
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &blk) ⇒ Object
80
81
82
83
84
|
# File 'lib/redis/em-connection-pool.rb', line 80
def method_missing(method, *args, &blk)
execute do |conn|
conn.__send__(method, *args, &blk)
end
end
|
Instance Method Details
#execute ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/redis/em-connection-pool.rb', line 50
def execute
f = Fiber.current
begin
until (conn = acquire f)
@queue << f
Fiber.yield
end
yield conn
ensure
release(f)
end
end
|
#multi(&blk) ⇒ Object
44
45
46
47
48
|
# File 'lib/redis/em-connection-pool.rb', line 44
def multi(&blk)
execute do |redis|
redis.multi(&blk)
end
end
|