class Pipeline
Send multiple commands without waiting for the response, instead of sending them one by one.
Nested
Definitions
def initialize(pool)
Initialize a new pipeline context.
Signature
-
parameter
pool
Pool
The connection pool to use.
Implementation
def initialize(pool)
super(pool)
@count = 0
@sync = nil
end
def flush(count = 0)
Flush responses.
Implementation
def flush(count = 0)
while @count > count
read_response
end
end
def collect
Collect all pending responses.
Signature
-
yields
{...}
Optional block to execute while collecting responses.
-
returns
Array
Array of all responses if no block given.
Implementation
def collect
if block_given?
flush
yield
end
@count.times.map{read_response}
end
def sync
Get a synchronous wrapper for this pipeline.
Signature
-
returns
Sync
A synchronous wrapper that executes commands immediately.
Implementation
def sync
@sync ||= Sync.new(self)
end
def write_request(*)
This method just accumulates the commands and their params.
Implementation
def write_request(*)
super
@count += 1
end
def call(command, *arguments)
This method just accumulates the commands and their params.
Implementation
def call(command, *arguments)
write_request(command, *arguments)
return nil
end
def read_response
Read a response from the pipeline.
Signature
-
returns
Object
The next response in the pipeline.
Implementation
def read_response
if @count > 0
@count -= 1
super
else
raise RuntimeError, "No more responses available!"
end
end
def close
Close the pipeline and flush all pending responses.
Implementation
def close
flush
ensure
super
end