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
-
#db ⇒ Object
Returns the value of attribute db.
-
#futures ⇒ Object
readonly
Returns the value of attribute futures.
Instance Method Summary collapse
- #call(command, &block) ⇒ Object
- #call_pipeline(pipeline) ⇒ Object
- #commands ⇒ Object
- #finish(replies, &blk) ⇒ Object
-
#initialize ⇒ Pipeline
constructor
A new instance of Pipeline.
- #shutdown? ⇒ Boolean
- #with_reconnect(val = true) ⇒ Object
- #with_reconnect? ⇒ Boolean
- #without_reconnect(&blk) ⇒ Object
- #without_reconnect? ⇒ Boolean
Constructor Details
#initialize ⇒ Pipeline
Returns a new instance of Pipeline.
13 14 15 16 17 |
# File 'lib/redis/pipeline.rb', line 13 def initialize @with_reconnect = true @shutdown = false @futures = [] end |
Instance Attribute Details
#db ⇒ Object
Returns the value of attribute db.
9 10 11 |
# File 'lib/redis/pipeline.rb', line 9 def db @db end |
#futures ⇒ Object (readonly)
Returns the value of attribute futures.
11 12 13 |
# File 'lib/redis/pipeline.rb', line 11 def futures @futures end |
Instance Method Details
#call(command, &block) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/redis/pipeline.rb', line 31 def call(command, &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) @futures << future future end |
#call_pipeline(pipeline) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/redis/pipeline.rb', line 40 def call_pipeline(pipeline) @shutdown = true if pipeline.shutdown? @futures.concat(pipeline.futures) @db = pipeline.db nil end |
#commands ⇒ Object
47 48 49 |
# File 'lib/redis/pipeline.rb', line 47 def commands @futures.map { |f| f._command } end |
#finish(replies, &blk) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/redis/pipeline.rb', line 60 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 |
#with_reconnect(val = true) ⇒ Object
51 52 53 54 |
# File 'lib/redis/pipeline.rb', line 51 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
56 57 58 |
# File 'lib/redis/pipeline.rb', line 56 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 |