Class: Redis::Pipeline
- Inherits:
-
Object
show all
- Defined in:
- lib/redis/pipeline.rb
Defined Under Namespace
Classes: Multi
Constant Summary
collapse
- REDIS_INTERNAL_PATH =
File.expand_path("..", __dir__).freeze
- STDLIB_PATH =
Redis use MonitorMixin#synchronize and this class use DelegateClass which we want to filter out. Both are in the stdlib so we can simply filter the entire stdlib out.
File.expand_path("..", MonitorMixin.instance_method(:synchronize).source_location.first).freeze
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(client) ⇒ Pipeline
Returns a new instance of Pipeline.
73
74
75
76
77
78
|
# File 'lib/redis/pipeline.rb', line 73
def initialize(client)
@client = client.is_a?(Pipeline) ? client.client : client
@with_reconnect = true
@shutdown = false
@futures = []
end
|
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
69
70
71
|
# File 'lib/redis/pipeline.rb', line 69
def client
@client
end
|
#db ⇒ Object
Returns the value of attribute db.
68
69
70
|
# File 'lib/redis/pipeline.rb', line 68
def db
@db
end
|
#futures ⇒ Object
Returns the value of attribute futures.
71
72
73
|
# File 'lib/redis/pipeline.rb', line 71
def futures
@futures
end
|
Class Method Details
.deprecation_warning(method, caller_locations) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/redis/pipeline.rb', line 47
def deprecation_warning(method, caller_locations) callsite = caller_locations.find { |l| !l.path.start_with?(REDIS_INTERNAL_PATH, STDLIB_PATH) }
callsite ||= caller_locations.last ::Redis.deprecate! <<~MESSAGE
Pipelining commands on a Redis instance is deprecated and will be removed in Redis 5.0.0.
redis.#{method} do
redis.get("key")
end
should be replaced by
redis.#{method} do |pipeline|
pipeline.get("key")
end
(called from #{callsite}}
MESSAGE
end
|
Instance Method Details
#call(command, timeout: nil, &block) ⇒ Object
100
101
102
103
104
105
106
107
|
# File 'lib/redis/pipeline.rb', line 100
def call(command, timeout: nil, &block)
@shutdown = true if command.first == :shutdown
future = Future.new(command, block, timeout)
@futures << future
future
end
|
#call_pipeline(pipeline) ⇒ Object
113
114
115
116
117
118
|
# File 'lib/redis/pipeline.rb', line 113
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
109
110
111
|
# File 'lib/redis/pipeline.rb', line 109
def call_with_timeout(command, timeout, &block)
call(command, timeout: timeout, &block)
end
|
#commands ⇒ Object
120
121
122
|
# File 'lib/redis/pipeline.rb', line 120
def commands
@futures.map(&:_command)
end
|
#empty? ⇒ Boolean
96
97
98
|
# File 'lib/redis/pipeline.rb', line 96
def empty?
@futures.empty?
end
|
#finish(replies, &blk) ⇒ Object
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/redis/pipeline.rb', line 137
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
92
93
94
|
# File 'lib/redis/pipeline.rb', line 92
def shutdown?
@shutdown
end
|
#timeout ⇒ Object
80
81
82
|
# File 'lib/redis/pipeline.rb', line 80
def timeout
client.timeout
end
|
#timeouts ⇒ Object
124
125
126
|
# File 'lib/redis/pipeline.rb', line 124
def timeouts
@futures.map(&:timeout)
end
|
#with_reconnect(val = true) ⇒ Object
128
129
130
131
|
# File 'lib/redis/pipeline.rb', line 128
def with_reconnect(val = true)
@with_reconnect = false unless val
yield
end
|
#with_reconnect? ⇒ Boolean
84
85
86
|
# File 'lib/redis/pipeline.rb', line 84
def with_reconnect?
@with_reconnect
end
|
#without_reconnect(&blk) ⇒ Object
133
134
135
|
# File 'lib/redis/pipeline.rb', line 133
def without_reconnect(&blk)
with_reconnect(false, &blk)
end
|
#without_reconnect? ⇒ Boolean
88
89
90
|
# File 'lib/redis/pipeline.rb', line 88
def without_reconnect?
!@with_reconnect
end
|