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.



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

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.



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

def client
  @client
end

#dbObject

Returns the value of attribute db.



3
4
5
# File 'lib/redis/pipeline.rb', line 3

def db
  @db
end

#futuresObject (readonly)

Returns the value of attribute futures.



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

def futures
  @futures
end

Instance Method Details

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



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

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



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

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



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

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

#commandsObject



55
56
57
# File 'lib/redis/pipeline.rb', line 55

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

#empty?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/redis/pipeline.rb', line 31

def empty?
  @futures.empty?
end

#finish(replies, &blk) ⇒ Object



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

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)


27
28
29
# File 'lib/redis/pipeline.rb', line 27

def shutdown?
  @shutdown
end

#timeoutObject



15
16
17
# File 'lib/redis/pipeline.rb', line 15

def timeout
  client.timeout
end

#timeoutsObject



59
60
61
# File 'lib/redis/pipeline.rb', line 59

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

#with_reconnect(val = true) ⇒ Object



63
64
65
66
# File 'lib/redis/pipeline.rb', line 63

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

#with_reconnect?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/redis/pipeline.rb', line 19

def with_reconnect?
  @with_reconnect
end

#without_reconnect(&blk) ⇒ Object



68
69
70
# File 'lib/redis/pipeline.rb', line 68

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

#without_reconnect?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/redis/pipeline.rb', line 23

def without_reconnect?
  !@with_reconnect
end