Class: Async::Redis::Context::Pipeline
- Includes:
- Protocol::Redis::Methods
- Defined in:
- lib/async/redis/context/pipeline.rb
Overview
Send multiple commands without waiting for the response, instead of sending them one by one.
Direct Known Subclasses
Defined Under Namespace
Classes: Sync
Instance Method Summary collapse
-
#call(command, *arguments) ⇒ Object
This method just accumulates the commands and their params.
- #close ⇒ Object
- #collect ⇒ Object
-
#flush(count = 0) ⇒ Object
Flush responses.
-
#initialize(pool) ⇒ Pipeline
constructor
A new instance of Pipeline.
- #read_response ⇒ Object
- #sync ⇒ Object
-
#write_request ⇒ Object
This method just accumulates the commands and their params.
Constructor Details
#initialize(pool) ⇒ Pipeline
Returns a new instance of Pipeline.
34 35 36 37 38 39 |
# File 'lib/async/redis/context/pipeline.rb', line 34 def initialize(pool) super(pool) @count = 0 @sync = nil end |
Instance Method Details
#call(command, *arguments) ⇒ Object
This method just accumulates the commands and their params.
61 62 63 64 65 |
# File 'lib/async/redis/context/pipeline.rb', line 61 def call(command, *arguments) write_request(command, *arguments) return nil end |
#close ⇒ Object
82 83 84 85 86 |
# File 'lib/async/redis/context/pipeline.rb', line 82 def close flush ensure super end |
#collect ⇒ Object
76 77 78 79 80 |
# File 'lib/async/redis/context/pipeline.rb', line 76 def collect yield @count.times.map{read_response} end |
#flush(count = 0) ⇒ Object
Flush responses.
43 44 45 46 47 |
# File 'lib/async/redis/context/pipeline.rb', line 43 def flush(count = 0) while @count > count read_response end end |
#read_response ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/async/redis/context/pipeline.rb', line 67 def read_response if @count > 0 @count -= 1 super else raise RuntimeError, "No more responses available!" end end |
#sync ⇒ Object
49 50 51 |
# File 'lib/async/redis/context/pipeline.rb', line 49 def sync @sync ||= Sync.new(self) end |
#write_request ⇒ Object
This method just accumulates the commands and their params.
54 55 56 57 58 |
# File 'lib/async/redis/context/pipeline.rb', line 54 def write_request(*) super @count += 1 end |