Class: Redis::Pipeline

Inherits:
Object
  • Object
show all
Defined in:
lib/redis/pipeline.rb

Direct Known Subclasses

Multi

Defined Under Namespace

Classes: Multi

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePipeline

Returns a new instance of Pipeline.



11
12
13
14
15
# File 'lib/redis/pipeline.rb', line 11

def initialize
  @with_reconnect = true
  @shutdown = false
  @futures = []
end

Instance Attribute Details

#futuresObject (readonly)

Returns the value of attribute futures.



9
10
11
# File 'lib/redis/pipeline.rb', line 9

def futures
  @futures
end

Instance Method Details

#call(command, &block) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/redis/pipeline.rb', line 29

def call(command, &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)
  @futures << future
  future
end

#call_pipeline(pipeline) ⇒ Object



38
39
40
41
42
# File 'lib/redis/pipeline.rb', line 38

def call_pipeline(pipeline)
  @shutdown = true if pipeline.shutdown?
  @futures.concat(pipeline.futures)
  nil
end

#commandsObject



44
45
46
# File 'lib/redis/pipeline.rb', line 44

def commands
  @futures.map { |f| f._command }
end

#finish(replies, &blk) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/redis/pipeline.rb', line 57

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?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/redis/pipeline.rb', line 25

def shutdown?
  @shutdown
end

#with_reconnect(val = true) ⇒ Object



48
49
50
51
# File 'lib/redis/pipeline.rb', line 48

def with_reconnect(val=true)
  @with_reconnect = false unless val
  yield
end

#with_reconnect?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/redis/pipeline.rb', line 17

def with_reconnect?
  @with_reconnect
end

#without_reconnect(&blk) ⇒ Object



53
54
55
# File 'lib/redis/pipeline.rb', line 53

def without_reconnect(&blk)
  with_reconnect(false, &blk)
end

#without_reconnect?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/redis/pipeline.rb', line 21

def without_reconnect?
  !@with_reconnect
end