Class: Redis::Pipeline
- Inherits:
-
Object
- Object
- Redis::Pipeline
- Defined in:
- lib/redis/pipeline.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Multi
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#db ⇒ Object
Returns the value of attribute db.
-
#futures ⇒ Object
readonly
Returns the value of attribute futures.
Instance Method Summary collapse
- #call(command, timeout: nil, &block) ⇒ Object
- #call_pipeline(pipeline) ⇒ Object
- #call_with_timeout(command, timeout, &block) ⇒ Object
- #commands ⇒ Object
- #empty? ⇒ Boolean
- #finish(replies, &blk) ⇒ Object
-
#initialize(client) ⇒ Pipeline
constructor
A new instance of Pipeline.
- #shutdown? ⇒ Boolean
- #timeout ⇒ Object
- #timeouts ⇒ Object
- #with_reconnect(val = true) ⇒ Object
- #with_reconnect? ⇒ Boolean
- #without_reconnect(&blk) ⇒ Object
- #without_reconnect? ⇒ Boolean
Constructor Details
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
4 5 6 |
# File 'lib/redis/pipeline.rb', line 4 def client @client end |
#db ⇒ Object
Returns the value of attribute db.
3 4 5 |
# File 'lib/redis/pipeline.rb', line 3 def db @db end |
#futures ⇒ Object (readonly)
Returns the value of attribute futures.
6 7 8 |
# File 'lib/redis/pipeline.rb', line 6 def futures @futures end |
Instance Method Details
#call(command, timeout: nil, &block) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/redis/pipeline.rb', line 35 def call(command, timeout: nil, &block) # A pipeline that contains a shutdown should not raise ECONNRESET when # the connection is gone. @shutdown = true if command.first == :shutdown future = Future.new(command, block, timeout) @futures << future future end |
#call_pipeline(pipeline) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/redis/pipeline.rb', line 48 def call_pipeline(pipeline) @shutdown = true if pipeline.shutdown? @futures.concat(pipeline.futures) @db = pipeline.db nil end |
#call_with_timeout(command, timeout, &block) ⇒ Object
44 45 46 |
# File 'lib/redis/pipeline.rb', line 44 def call_with_timeout(command, timeout, &block) call(command, timeout: timeout, &block) end |
#commands ⇒ Object
55 56 57 |
# File 'lib/redis/pipeline.rb', line 55 def commands @futures.map(&:_command) end |
#empty? ⇒ Boolean
31 32 33 |
# File 'lib/redis/pipeline.rb', line 31 def empty? @futures.empty? end |
#finish(replies, &blk) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/redis/pipeline.rb', line 72 def finish(replies, &blk) if blk futures.each_with_index.map do |future, i| future._set(blk.call(replies[i])) end else futures.each_with_index.map do |future, i| future._set(replies[i]) end end end |
#shutdown? ⇒ Boolean
27 28 29 |
# File 'lib/redis/pipeline.rb', line 27 def shutdown? @shutdown end |
#timeout ⇒ Object
15 16 17 |
# File 'lib/redis/pipeline.rb', line 15 def timeout client.timeout end |
#timeouts ⇒ Object
59 60 61 |
# File 'lib/redis/pipeline.rb', line 59 def timeouts @futures.map(&:timeout) end |
#with_reconnect(val = true) ⇒ Object
63 64 65 66 |
# File 'lib/redis/pipeline.rb', line 63 def with_reconnect(val=true) @with_reconnect = false unless val yield end |
#with_reconnect? ⇒ Boolean
19 20 21 |
# File 'lib/redis/pipeline.rb', line 19 def with_reconnect? @with_reconnect end |
#without_reconnect(&blk) ⇒ Object
68 69 70 |
# File 'lib/redis/pipeline.rb', line 68 def without_reconnect(&blk) with_reconnect(false, &blk) end |
#without_reconnect? ⇒ Boolean
23 24 25 |
# File 'lib/redis/pipeline.rb', line 23 def without_reconnect? !@with_reconnect end |