redis 4.5.1 → 4.7.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,80 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "delegate"
4
+
3
5
  class Redis
6
+ class PipelinedConnection
7
+ def initialize(pipeline)
8
+ @pipeline = pipeline
9
+ end
10
+
11
+ include Commands
12
+
13
+ def db
14
+ @pipeline.db
15
+ end
16
+
17
+ def db=(db)
18
+ @pipeline.db = db
19
+ end
20
+
21
+ def pipelined
22
+ yield self
23
+ end
24
+
25
+ def call_pipeline(pipeline)
26
+ @pipeline.call_pipeline(pipeline)
27
+ nil
28
+ end
29
+
30
+ private
31
+
32
+ def synchronize
33
+ yield self
34
+ end
35
+
36
+ def send_command(command, &block)
37
+ @pipeline.call(command, &block)
38
+ end
39
+
40
+ def send_blocking_command(command, timeout, &block)
41
+ @pipeline.call_with_timeout(command, timeout, &block)
42
+ end
43
+ end
44
+
4
45
  class Pipeline
46
+ REDIS_INTERNAL_PATH = File.expand_path("..", __dir__).freeze
47
+ # Redis use MonitorMixin#synchronize and this class use DelegateClass which we want to filter out.
48
+ # Both are in the stdlib so we can simply filter the entire stdlib out.
49
+ STDLIB_PATH = File.expand_path("..", MonitorMixin.instance_method(:synchronize).source_location.first).freeze
50
+
51
+ class << self
52
+ def deprecation_warning(method, caller_locations) # :nodoc:
53
+ callsite = caller_locations.find { |l| !l.path.start_with?(REDIS_INTERNAL_PATH, STDLIB_PATH) }
54
+ callsite ||= caller_locations.last # The caller_locations should be large enough, but just in case.
55
+ ::Redis.deprecate! <<~MESSAGE
56
+ Pipelining commands on a Redis instance is deprecated and will be removed in Redis 5.0.0.
57
+
58
+ redis.#{method} do
59
+ redis.get("key")
60
+ end
61
+
62
+ should be replaced by
63
+
64
+ redis.#{method} do |pipeline|
65
+ pipeline.get("key")
66
+ end
67
+
68
+ (called from #{callsite}}
69
+ MESSAGE
70
+ end
71
+ end
72
+
5
73
  attr_accessor :db
6
74
  attr_reader :client
7
75
 
8
76
  attr :futures
77
+ alias materialized_futures futures
9
78
 
10
79
  def initialize(client)
11
80
  @client = client.is_a?(Pipeline) ? client.client : client
@@ -49,7 +118,7 @@ class Redis
49
118
 
50
119
  def call_pipeline(pipeline)
51
120
  @shutdown = true if pipeline.shutdown?
52
- @futures.concat(pipeline.futures)
121
+ @futures.concat(pipeline.materialized_futures)
53
122
  @db = pipeline.db
54
123
  nil
55
124
  end
@@ -106,6 +175,18 @@ class Redis
106
175
  end
107
176
  end
108
177
 
178
+ def materialized_futures
179
+ if empty?
180
+ []
181
+ else
182
+ [
183
+ Future.new([:multi], nil, 0),
184
+ *futures,
185
+ MultiFuture.new(futures)
186
+ ]
187
+ end
188
+ end
189
+
109
190
  def timeouts
110
191
  if empty?
111
192
  []
@@ -124,6 +205,36 @@ class Redis
124
205
  end
125
206
  end
126
207
 
208
+ class DeprecatedPipeline < DelegateClass(Pipeline)
209
+ def initialize(pipeline)
210
+ super(pipeline)
211
+ @deprecation_displayed = false
212
+ end
213
+
214
+ def __getobj__
215
+ unless @deprecation_displayed
216
+ Pipeline.deprecation_warning("pipelined", Kernel.caller_locations(1, 10))
217
+ @deprecation_displayed = true
218
+ end
219
+ @delegate_dc_obj
220
+ end
221
+ end
222
+
223
+ class DeprecatedMulti < DelegateClass(Pipeline::Multi)
224
+ def initialize(pipeline)
225
+ super(pipeline)
226
+ @deprecation_displayed = false
227
+ end
228
+
229
+ def __getobj__
230
+ unless @deprecation_displayed
231
+ Pipeline.deprecation_warning("multi", Kernel.caller_locations(1, 10))
232
+ @deprecation_displayed = true
233
+ end
234
+ @delegate_dc_obj
235
+ end
236
+ end
237
+
127
238
  class FutureNotReady < RuntimeError
128
239
  def initialize
129
240
  super("Value will be available once the pipeline executes.")
@@ -143,11 +254,11 @@ class Redis
143
254
  end
144
255
 
145
256
  def ==(_other)
146
- message = +"The methods == and != are deprecated for Redis::Future and will be removed in 4.2.0"
257
+ message = +"The methods == and != are deprecated for Redis::Future and will be removed in 5.0.0"
147
258
  message << " - You probably meant to call .value == or .value !="
148
259
  message << " (#{::Kernel.caller(1, 1).first})\n"
149
260
 
150
- ::Kernel.warn(message)
261
+ ::Redis.deprecate!(message)
151
262
 
152
263
  super
153
264
  end
@@ -178,4 +289,18 @@ class Redis
178
289
  Future
179
290
  end
180
291
  end
292
+
293
+ class MultiFuture < Future
294
+ def initialize(futures)
295
+ @futures = futures
296
+ @command = [:exec]
297
+ end
298
+
299
+ def _set(replies)
300
+ @futures.each_with_index do |future, index|
301
+ future._set(replies[index])
302
+ end
303
+ replies
304
+ end
305
+ end
181
306
  end
data/lib/redis/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Redis
4
- VERSION = '4.5.1'
4
+ VERSION = '4.7.1'
5
5
  end