class Redis::Client

def call_pipelined(pipeline)

def call_pipelined(pipeline)
  return [] if pipeline.futures.empty?
  # The method #ensure_connected (called from #process) reconnects once on
  # I/O errors. To make an effort in making sure that commands are not
  # executed more than once, only allow reconnection before the first reply
  # has been read. When an error occurs after the first reply has been
  # read, retrying would re-execute the entire pipeline, thus re-issuing
  # already successfully executed commands. To circumvent this, don't retry
  # after the first reply has been read successfully.
  commands = pipeline.commands
  result = Array.new(commands.size)
  reconnect = @reconnect
  begin
    exception = nil
    process(commands) do
      pipeline.timeouts.each_with_index do |timeout, i|
        reply = if timeout
          with_socket_timeout(timeout) { read }
        else
          read
        end
        result[i] = reply
        @reconnect = false
        exception = reply if exception.nil? && reply.is_a?(CommandError)
      end
    end
    raise exception if exception
  ensure
    @reconnect = reconnect
  end
  result
end