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.
7 8 9 10 11 |
# File 'lib/redis/pipeline.rb', line 7 def initialize @with_reconnect = true @shutdown = false @futures = [] end |
Instance Attribute Details
#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.
5 6 7 |
# File 'lib/redis/pipeline.rb', line 5 def futures @futures end |
Instance Method Details
#call(command, &block) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/redis/pipeline.rb', line 25 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
34 35 36 37 38 39 |
# File 'lib/redis/pipeline.rb', line 34 def call_pipeline(pipeline) @shutdown = true if pipeline.shutdown? @futures.concat(pipeline.futures) @db = pipeline.db nil end |
#commands ⇒ Object
41 42 43 |
# File 'lib/redis/pipeline.rb', line 41 def commands @futures.map { |f| f._command } end |
#finish(replies, &blk) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/redis/pipeline.rb', line 54 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
21 22 23 |
# File 'lib/redis/pipeline.rb', line 21 def shutdown? @shutdown end |
#with_reconnect(val = true) ⇒ Object
45 46 47 48 |
# File 'lib/redis/pipeline.rb', line 45 def with_reconnect(val=true) @with_reconnect = false unless val yield end |
#with_reconnect? ⇒ Boolean
13 14 15 |
# File 'lib/redis/pipeline.rb', line 13 def with_reconnect? @with_reconnect end |
#without_reconnect(&blk) ⇒ Object
50 51 52 |
# File 'lib/redis/pipeline.rb', line 50 def without_reconnect(&blk) with_reconnect(false, &blk) end |
#without_reconnect? ⇒ Boolean
17 18 19 |
# File 'lib/redis/pipeline.rb', line 17 def without_reconnect? !@with_reconnect end |