class Redis::Pipeline

Attributes

client[R]
db[RW]
futures[R]

Public Class Methods

new(client) click to toggle source
# File lib/redis/pipeline.rb, line 9
def initialize(client)
  @client = client.is_a?(Pipeline) ? client.client : client
  @with_reconnect = true
  @shutdown = false
  @futures = []
end

Public Instance Methods

call(command, timeout: nil, &block) click to toggle source
# File lib/redis/pipeline.rb, line 36
def call(command, timeout: nil, &block)
  # A pipeline that contains a shutdown should not raise ECONNRESET when
  # the connection is gone.
  @shutdown = true if command.first == :shutdown
  future = Future.new(command, block, timeout)
  @futures << future
  future
end
call_pipeline(pipeline) click to toggle source
# File lib/redis/pipeline.rb, line 49
def call_pipeline(pipeline)
  @shutdown = true if pipeline.shutdown?
  @futures.concat(pipeline.futures)
  @db = pipeline.db
  nil
end
call_with_timeout(command, timeout, &block) click to toggle source
# File lib/redis/pipeline.rb, line 45
def call_with_timeout(command, timeout, &block)
  call(command, timeout: timeout, &block)
end
commands() click to toggle source
# File lib/redis/pipeline.rb, line 56
def commands
  @futures.map(&:_command)
end
empty?() click to toggle source
# File lib/redis/pipeline.rb, line 32
def empty?
  @futures.empty?
end
finish(replies, &blk) click to toggle source
# File lib/redis/pipeline.rb, line 73
def finish(replies, &blk)
  if blk
    futures.each_with_index.map do |future, i|
      future._set(blk.call(replies[i]))
    end
  else
    futures.each_with_index.map do |future, i|
      future._set(replies[i])
    end
  end
end
shutdown?() click to toggle source
# File lib/redis/pipeline.rb, line 28
def shutdown?
  @shutdown
end
timeout() click to toggle source
# File lib/redis/pipeline.rb, line 16
def timeout
  client.timeout
end
timeouts() click to toggle source
# File lib/redis/pipeline.rb, line 60
def timeouts
  @futures.map(&:timeout)
end
with_reconnect(val = true) { || ... } click to toggle source
# File lib/redis/pipeline.rb, line 64
def with_reconnect(val = true)
  @with_reconnect = false unless val
  yield
end
with_reconnect?() click to toggle source
# File lib/redis/pipeline.rb, line 20
def with_reconnect?
  @with_reconnect
end
without_reconnect(&blk) click to toggle source
# File lib/redis/pipeline.rb, line 69
def without_reconnect(&blk)
  with_reconnect(false, &blk)
end
without_reconnect?() click to toggle source
# File lib/redis/pipeline.rb, line 24
def without_reconnect?
  !@with_reconnect
end