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

#initialize(client) ⇒ Pipeline

Returns a new instance of Pipeline.



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

def initialize(client)
  @client = client.is_a?(Pipeline) ? client.client : client
  @with_reconnect = true
  @shutdown = false
  @futures = []
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/redis/pipeline.rb', line 6

def client
  @client
end

#dbObject

Returns the value of attribute db.



5
6
7
# File 'lib/redis/pipeline.rb', line 5

def db
  @db
end

#futuresObject (readonly)

Returns the value of attribute futures.



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

def futures
  @futures
end

Instance Method Details

#call(command, timeout: nil, &block) ⇒ Object



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

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) ⇒ Object



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

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

#call_with_timeout(command, timeout, &block) ⇒ Object



46
47
48
# File 'lib/redis/pipeline.rb', line 46

def call_with_timeout(command, timeout, &block)
  call(command, timeout: timeout, &block)
end

#commandsObject



57
58
59
# File 'lib/redis/pipeline.rb', line 57

def commands
  @futures.map(&:_command)
end

#empty?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/redis/pipeline.rb', line 33

def empty?
  @futures.empty?
end

#finish(replies, &blk) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/redis/pipeline.rb', line 74

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)


29
30
31
# File 'lib/redis/pipeline.rb', line 29

def shutdown?
  @shutdown
end

#timeoutObject



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

def timeout
  client.timeout
end

#timeoutsObject



61
62
63
# File 'lib/redis/pipeline.rb', line 61

def timeouts
  @futures.map(&:timeout)
end

#with_reconnect(val = true) ⇒ Object



65
66
67
68
# File 'lib/redis/pipeline.rb', line 65

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

#with_reconnect?Boolean

Returns:

  • (Boolean)


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

def with_reconnect?
  @with_reconnect
end

#without_reconnect(&blk) ⇒ Object



70
71
72
# File 'lib/redis/pipeline.rb', line 70

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

#without_reconnect?Boolean

Returns:

  • (Boolean)


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

def without_reconnect?
  !@with_reconnect
end