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.
6 7 8 |
# File 'lib/redis/pipeline.rb', line 6 def client @client end |
#db ⇒ Object
Returns the value of attribute db.
5 6 7 |
# File 'lib/redis/pipeline.rb', line 5 def db @db end |
#futures ⇒ Object (readonly)
Returns the value of attribute futures.
8 9 10 |
# File 'lib/redis/pipeline.rb', line 8 def futures @futures end |
Instance Method Details
#call(command, timeout: nil, &block) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/redis/pipeline.rb', line 37 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
50 51 52 53 54 55 |
# File 'lib/redis/pipeline.rb', line 50 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
46 47 48 |
# File 'lib/redis/pipeline.rb', line 46 def call_with_timeout(command, timeout, &block) call(command, timeout: timeout, &block) end |
#commands ⇒ Object
57 58 59 |
# File 'lib/redis/pipeline.rb', line 57 def commands @futures.map(&:_command) end |
#empty? ⇒ Boolean
33 34 35 |
# File 'lib/redis/pipeline.rb', line 33 def empty? @futures.empty? end |
#finish(replies, &blk) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/redis/pipeline.rb', line 74 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
29 30 31 |
# File 'lib/redis/pipeline.rb', line 29 def shutdown? @shutdown end |
#timeout ⇒ Object
17 18 19 |
# File 'lib/redis/pipeline.rb', line 17 def timeout client.timeout end |
#timeouts ⇒ Object
61 62 63 |
# File 'lib/redis/pipeline.rb', line 61 def timeouts @futures.map(&:timeout) end |
#with_reconnect(val = true) ⇒ Object
65 66 67 68 |
# File 'lib/redis/pipeline.rb', line 65 def with_reconnect(val = true) @with_reconnect = false unless val yield end |
#with_reconnect? ⇒ Boolean
21 22 23 |
# File 'lib/redis/pipeline.rb', line 21 def with_reconnect? @with_reconnect end |
#without_reconnect(&blk) ⇒ Object
70 71 72 |
# File 'lib/redis/pipeline.rb', line 70 def without_reconnect(&blk) with_reconnect(false, &blk) end |
#without_reconnect? ⇒ Boolean
25 26 27 |
# File 'lib/redis/pipeline.rb', line 25 def without_reconnect? !@with_reconnect end |