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 Attribute Summary collapse
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
Instance Method Summary collapse
- #acquire ⇒ Object
- #close ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(limit = nil, &block) ⇒ Pool
constructor
A new instance of Pool.
-
#release(resource) ⇒ Object
Make the resource resources and let waiting tasks know that there is something resources.
- #to_s ⇒ Object
Constructor Details
Instance Attribute Details
#resources ⇒ Object (readonly)
Returns the value of attribute resources.
40 41 42 |
# File 'lib/async/redis/pool.rb', line 40 def resources @resources end |
Instance Method Details
#acquire ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/async/redis/pool.rb', line 46 def acquire resource = wait_for_resource return resource unless block_given? begin yield resource ensure release(resource) end end |
#close ⇒ Object
68 69 70 71 72 73 |
# File 'lib/async/redis/pool.rb', line 68 def close @resources.each(&:close) @resources.clear @active = 0 end |
#empty? ⇒ Boolean
42 43 44 |
# File 'lib/async/redis/pool.rb', line 42 def empty? @resources.empty? end |
#release(resource) ⇒ Object
Make the resource resources and let waiting tasks know that there is something resources.
59 60 61 62 63 64 65 66 |
# File 'lib/async/redis/pool.rb', line 59 def release(resource) # A resource that is not good should also not be reusable. unless resource.closed? reuse(resource) else retire(resource) end end |
#to_s ⇒ Object
75 76 77 |
# File 'lib/async/redis/pool.rb', line 75 def to_s "\#<#{self.class} resources=#{resources.count} limit=#{@limit}>" end |