class Redis::Pipeline::Multi

def commands

def commands
  if empty?
    []
  else
    [[:multi]] + super + [[:exec]]
  end
end

def finish(replies)

def finish(replies)
  exec = replies.last
  return if exec.nil? # The transaction failed because of WATCH.
  # EXEC command failed.
  raise exec if exec.is_a?(CommandError)
  if exec.size < futures.size
    # Some command wasn't recognized by Redis.
    command_error = replies.detect { |r| r.is_a?(CommandError) }
    raise command_error
  end
  super(exec) do |reply|
    # Because an EXEC returns nested replies, hiredis won't be able to
    # convert an error reply to a CommandError instance itself. This is
    # specific to MULTI/EXEC, so we solve this here.
    reply.is_a?(::RuntimeError) ? CommandError.new(reply.message) : reply
  end
end

def materialized_futures

def materialized_futures
  if empty?
    []
  else
    [
      Future.new([:multi], nil, 0),
      *futures,
      MultiFuture.new(futures)
    ]
  end
end

def timeouts

def timeouts
  if empty?
    []
  else
    [nil, *super, nil]
  end
end