Class: Redis::Pipeline::Multi

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

Direct Known Subclasses

DeprecatedMulti

Constant Summary

Constants inherited from Redis::Pipeline

REDIS_INTERNAL_PATH, STDLIB_PATH

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, deprecation_warning, #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



180
181
182
183
184
185
186
# File 'lib/redis/pipeline.rb', line 180

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

#finish(replies) ⇒ Object



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/redis/pipeline.rb', line 150

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



172
173
174
175
176
177
178
# File 'lib/redis/pipeline.rb', line 172

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