Class: Redis::Pipeline::Multi

Inherits:
Redis::Pipeline show all
Defined in:
lib/redis/pipeline.rb

Instance Attribute Summary

Attributes inherited from Redis::Pipeline

#client, #db, #futures

Instance Method Summary collapse

Methods inherited from Redis::Pipeline

#call, #call_pipeline, #call_with_timeout, #empty?, #initialize, #shutdown?, #timeout, #with_reconnect, #with_reconnect?, #without_reconnect, #without_reconnect?

Constructor Details

This class inherits a constructor from Redis::Pipeline

Instance Method Details

#commandsObject



117
118
119
120
121
122
123
# File 'lib/redis/pipeline.rb', line 117

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

#finish(replies) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/redis/pipeline.rb', line 87

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

#timeoutsObject



109
110
111
112
113
114
115
# File 'lib/redis/pipeline.rb', line 109

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