Class: Redic::Pool
- Inherits:
-
Object
- Object
- Redic::Pool
- Defined in:
- lib/redic/pool.rb
Constant Summary collapse
- VERSION =
"1.0.1"
Instance Attribute Summary collapse
-
#pool ⇒ Object
readonly
Returns the value of attribute pool.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #call(*args) ⇒ Object
- #commit ⇒ Object
-
#initialize(url, options = {}) ⇒ Pool
constructor
A new instance of Pool.
- #queue(*args) ⇒ Object
Constructor Details
#initialize(url, options = {}) ⇒ Pool
Returns a new instance of Pool.
10 11 12 13 14 15 |
# File 'lib/redic/pool.rb', line 10 def initialize(url, = {}) @url = url @pool = ConnectionPool.new(size: .fetch(:size, 10)) { Redic.new(url) } @id = "redic-pool-#{object_id}" end |
Instance Attribute Details
#pool ⇒ Object (readonly)
Returns the value of attribute pool.
8 9 10 |
# File 'lib/redic/pool.rb', line 8 def pool @pool end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
7 8 9 |
# File 'lib/redic/pool.rb', line 7 def url @url end |
Instance Method Details
#call(*args) ⇒ Object
17 18 19 20 21 |
# File 'lib/redic/pool.rb', line 17 def call(*args) @pool.with do |client| client.call(*args) end end |
#commit ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/redic/pool.rb', line 28 def commit @pool.with do |client| Thread.current[@id].each do |args| client.queue(*args) end result = client.commit Thread.current[@id].clear result end end |
#queue(*args) ⇒ Object
23 24 25 26 |
# File 'lib/redic/pool.rb', line 23 def queue(*args) Thread.current[@id] || (Thread.current[@id] = []) Thread.current[@id] << args end |