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



198
199
200
201
202
203
204
# File 'lib/redis/pipeline.rb', line 198

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

#finish(replies) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/redis/pipeline.rb', line 156

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

#materialized_futuresObject



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

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

#timeoutsObject



190
191
192
193
194
195
196
# File 'lib/redis/pipeline.rb', line 190

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