Class: Redis2::Pipeline::Multi

Inherits:
Redis2::Pipeline show all
Defined in:
lib/redis2/pipeline.rb

Instance Attribute Summary

Attributes inherited from Redis2::Pipeline

#db, #futures

Instance Method Summary collapse

Methods inherited from Redis2::Pipeline

#call, #call_pipeline, #initialize, #shutdown?, #with_reconnect, #with_reconnect?, #without_reconnect, #without_reconnect?

Constructor Details

This class inherits a constructor from Redis2::Pipeline

Instance Method Details

#commandsObject



94
95
96
# File 'lib/redis2/pipeline.rb', line 94

def commands
  [[:multi]] + super + [[:exec]]
end

#finish(replies) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/redis2/pipeline.rb', line 73

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 Redis2.
    raise replies.detect { |r| r.is_a?(CommandError) }
  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