Class: Async::Redis::Pool
- Inherits:
-
Object
- Object
- Async::Redis::Pool
- Defined in:
- lib/async/redis/pool.rb
Overview
It might make sense to add support for pipelining redis.io/topics/pipelining We should be able to wrap the protocol so that write_request and read_response happen in lockstep. The only problem would be blocking operations. It might also be confusing if order of operations affects commands.
Instance Method Summary collapse
- #acquire ⇒ Object
- #close ⇒ Object
-
#initialize(limit = nil, &block) ⇒ Pool
constructor
A new instance of Pool.
-
#release(resource) ⇒ Object
Make the resource available and let waiting tasks know that there is something available.
Constructor Details
#initialize(limit = nil, &block) ⇒ Pool
Returns a new instance of Pool.
27 28 29 30 31 32 33 34 |
# File 'lib/async/redis/pool.rb', line 27 def initialize(limit = nil, &block) @available = [] @waiting = [] @limit = limit @constructor = block end |
Instance Method Details
#acquire ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/async/redis/pool.rb', line 36 def acquire resource = wait_for_next_available return resource unless block_given? begin yield resource ensure release(resource) end end |
#close ⇒ Object
57 58 59 60 |
# File 'lib/async/redis/pool.rb', line 57 def close @available.each(&:close) @available.clear end |
#release(resource) ⇒ Object
Make the resource available and let waiting tasks know that there is something available.
49 50 51 52 53 54 55 |
# File 'lib/async/redis/pool.rb', line 49 def release(resource) @available << resource if task = @waiting.pop task.resume end end |