Class: SolidRedis::Pool
- Inherits:
-
Object
- Object
- SolidRedis::Pool
- Defined in:
- lib/solid_redis/pool.rb
Instance Attribute Summary collapse
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #blocking_call(timeout, *command) ⇒ Object
- #blocking_call_v(timeout, command) ⇒ Object
- #call(*command) ⇒ Object
- #call_v(command) ⇒ Object
- #close ⇒ Object
-
#initialize(config, size: 5, timeout: 1.0) ⇒ Pool
constructor
A new instance of Pool.
- #pipelined(exception: true, &block) ⇒ Object
- #with ⇒ Object (also: #then)
Constructor Details
#initialize(config, size: 5, timeout: 1.0) ⇒ Pool
Returns a new instance of Pool.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/solid_redis/pool.rb', line 7 def initialize(config, size: 5, timeout: 1.0) @config = config @size = Integer(size) raise ArgumentError, "Pool size must be positive" unless @size.positive? @timeout = Float(timeout) raise ArgumentError, "Pool timeout must be positive" unless @timeout.positive? @available = [] @created = 0 @mutex = Mutex.new @resource = ConditionVariable.new @closed = false @owner = Ractor.current end |
Instance Attribute Details
#size ⇒ Object (readonly)
Returns the value of attribute size.
5 6 7 |
# File 'lib/solid_redis/pool.rb', line 5 def size @size end |
Instance Method Details
#blocking_call(timeout, *command) ⇒ Object
40 41 42 |
# File 'lib/solid_redis/pool.rb', line 40 def blocking_call(timeout, *command) with { |client| client.blocking_call_v(timeout, command) } end |
#blocking_call_v(timeout, command) ⇒ Object
44 45 46 |
# File 'lib/solid_redis/pool.rb', line 44 def blocking_call_v(timeout, command) with { |client| client.blocking_call_v(timeout, command) } end |
#call(*command) ⇒ Object
32 33 34 |
# File 'lib/solid_redis/pool.rb', line 32 def call(*command) with { |client| client.call(*command) } end |
#call_v(command) ⇒ Object
36 37 38 |
# File 'lib/solid_redis/pool.rb', line 36 def call_v(command) with { |client| client.call_v(command) } end |
#close ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/solid_redis/pool.rb', line 52 def close ensure_owner! clients = @mutex.synchronize do @closed = true @resource.broadcast @available.shift(@available.length) end clients.each(&:close) self end |
#pipelined(exception: true, &block) ⇒ Object
48 49 50 |
# File 'lib/solid_redis/pool.rb', line 48 def pipelined(exception: true, &block) with { |client| client.pipelined(exception: exception, &block) } end |
#with ⇒ Object Also known as: then
23 24 25 26 27 28 29 |
# File 'lib/solid_redis/pool.rb', line 23 def with ensure_owner! client = checkout yield client ensure checkin(client) if client end |