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, *args) ⇒ 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.
48 49 50 51 52 53 |
# File 'lib/async/redis/context/pipeline.rb', line 48 def initialize(pool) super(pool) @count = 0 @sync = nil end |
Instance Method Details
#call(command, *args) ⇒ Object
This method just accumulates the commands and their params.
75 76 77 78 79 |
# File 'lib/async/redis/context/pipeline.rb', line 75 def call(command, *args) write_request(command, *args) return nil end |
#close ⇒ Object
96 97 98 99 100 |
# File 'lib/async/redis/context/pipeline.rb', line 96 def close flush super end |
#collect ⇒ Object
90 91 92 93 94 |
# File 'lib/async/redis/context/pipeline.rb', line 90 def collect yield @count.times.map{read_response} end |
#flush(count = 0) ⇒ Object
Flush responses.
57 58 59 60 61 |
# File 'lib/async/redis/context/pipeline.rb', line 57 def flush(count = 0) while @count > count read_response end end |
#read_response ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/async/redis/context/pipeline.rb', line 81 def read_response if @count > 0 @count -= 1 super else raise RuntimeError, "No more responses available!" end end |
#sync ⇒ Object
63 64 65 |
# File 'lib/async/redis/context/pipeline.rb', line 63 def sync @sync ||= Sync.new(self) end |
#write_request ⇒ Object
This method just accumulates the commands and their params.
68 69 70 71 72 |
# File 'lib/async/redis/context/pipeline.rb', line 68 def write_request(*) super @count += 1 end |