redis 4.1.4 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Redis
3
4
  # Base error for all redis-rb errors.
4
5
  class BaseError < RuntimeError
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'zlib'
3
4
 
4
5
  class Redis
5
6
  class HashRing
6
-
7
7
  POINTS_PER_SERVER = 160 # this is the default in libmemcached
8
8
 
9
9
  attr_reader :ring, :sorted_keys, :replicas, :nodes
@@ -11,7 +11,7 @@ class Redis
11
11
  # nodes is a list of objects that have a proper to_s representation.
12
12
  # replicas indicates how many virtual points should be used pr. node,
13
13
  # replicas are required to improve the distribution.
14
- def initialize(nodes=[], replicas=POINTS_PER_SERVER)
14
+ def initialize(nodes = [], replicas = POINTS_PER_SERVER)
15
15
  @replicas = replicas
16
16
  @ring = {}
17
17
  @nodes = []
@@ -33,11 +33,11 @@ class Redis
33
33
  end
34
34
 
35
35
  def remove_node(node)
36
- @nodes.reject!{|n| n.id == node.id}
36
+ @nodes.reject! { |n| n.id == node.id }
37
37
  @replicas.times do |i|
38
38
  key = Zlib.crc32("#{node.id}:#{i}")
39
39
  @ring.delete(key)
40
- @sorted_keys.reject! {|k| k == key}
40
+ @sorted_keys.reject! { |k| k == key }
41
41
  end
42
42
  end
43
43
 
@@ -47,27 +47,29 @@ class Redis
47
47
  end
48
48
 
49
49
  def get_node_pos(key)
50
- return [nil,nil] if @ring.size == 0
50
+ return [nil, nil] if @ring.empty?
51
+
51
52
  crc = Zlib.crc32(key)
52
53
  idx = HashRing.binary_search(@sorted_keys, crc)
53
- return [@ring[@sorted_keys[idx]], idx]
54
+ [@ring[@sorted_keys[idx]], idx]
54
55
  end
55
56
 
56
57
  def iter_nodes(key)
57
- return [nil,nil] if @ring.size == 0
58
+ return [nil, nil] if @ring.empty?
59
+
58
60
  _, pos = get_node_pos(key)
59
61
  @ring.size.times do |n|
60
- yield @ring[@sorted_keys[(pos+n) % @ring.size]]
62
+ yield @ring[@sorted_keys[(pos + n) % @ring.size]]
61
63
  end
62
64
  end
63
65
 
64
66
  # Find the closest index in HashRing with value <= the given value
65
- def self.binary_search(ary, value, &block)
67
+ def self.binary_search(ary, value)
66
68
  upper = ary.size - 1
67
69
  lower = 0
68
70
  idx = 0
69
71
 
70
- while(lower <= upper) do
72
+ while lower <= upper
71
73
  idx = (lower + upper) / 2
72
74
  comp = ary[idx] <=> value
73
75
 
@@ -80,10 +82,8 @@ class Redis
80
82
  end
81
83
  end
82
84
 
83
- if upper < 0
84
- upper = ary.size - 1
85
- end
86
- return upper
85
+ upper = ary.size - 1 if upper < 0
86
+ upper
87
87
  end
88
88
  end
89
89
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Redis
3
4
  class Pipeline
4
5
  attr_accessor :db
@@ -61,7 +62,7 @@ class Redis
61
62
  @futures.map(&:timeout)
62
63
  end
63
64
 
64
- def with_reconnect(val=true)
65
+ def with_reconnect(val = true)
65
66
  @with_reconnect = false unless val
66
67
  yield
67
68
  end
@@ -93,7 +94,8 @@ class Redis
93
94
 
94
95
  if exec.size < futures.size
95
96
  # Some command wasn't recognized by Redis.
96
- raise replies.detect { |r| r.is_a?(CommandError) }
97
+ command_error = replies.detect { |r| r.is_a?(CommandError) }
98
+ raise command_error
97
99
  end
98
100
 
99
101
  super(exec) do |reply|
@@ -145,11 +147,7 @@ class Redis
145
147
  message << " - You probably meant to call .value == or .value !="
146
148
  message << " (#{::Kernel.caller(1, 1).first})\n"
147
149
 
148
- if defined?(::Warning)
149
- ::Warning.warn(message)
150
- else
151
- $stderr.puts(message)
152
- end
150
+ ::Kernel.warn(message)
153
151
 
154
152
  super
155
153
  end
@@ -168,7 +166,7 @@ class Redis
168
166
  end
169
167
 
170
168
  def value
171
- ::Kernel.raise(@object) if @object.kind_of?(::RuntimeError)
169
+ ::Kernel.raise(@object) if @object.is_a?(::RuntimeError)
172
170
  @object
173
171
  end
174
172
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Redis
3
4
  class SubscribedClient
4
5
  def initialize(client)
@@ -33,24 +34,21 @@ class Redis
33
34
  call([:punsubscribe, *channels])
34
35
  end
35
36
 
36
- protected
37
+ protected
37
38
 
38
39
  def subscription(start, stop, channels, block, timeout = 0)
39
40
  sub = Subscription.new(&block)
40
41
 
41
42
  unsubscribed = false
42
43
 
43
- begin
44
- @client.call_loop([start, *channels], timeout) do |line|
45
- type, *rest = line
46
- sub.callbacks[type].call(*rest)
47
- unsubscribed = type == stop && rest.last == 0
48
- break if unsubscribed
49
- end
50
- ensure
51
- # No need to unsubscribe here. The real client closes the connection
52
- # whenever an exception is raised (see #ensure_connected).
44
+ @client.call_loop([start, *channels], timeout) do |line|
45
+ type, *rest = line
46
+ sub.callbacks[type].call(*rest)
47
+ unsubscribed = type == stop && rest.last == 0
48
+ break if unsubscribed
53
49
  end
50
+ # No need to unsubscribe here. The real client closes the connection
51
+ # whenever an exception is raised (see #ensure_connected).
54
52
  end
55
53
  end
56
54
 
@@ -59,7 +57,7 @@ class Redis
59
57
 
60
58
  def initialize
61
59
  @callbacks = Hash.new do |hash, key|
62
- hash[key] = lambda { |*_| }
60
+ hash[key] = ->(*_) {}
63
61
  end
64
62
 
65
63
  yield(self)
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Redis
3
- VERSION = '4.1.4'
4
+ VERSION = '4.2.0'
4
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.4
4
+ version: 4.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ezra Zygmuntowicz
@@ -16,10 +16,10 @@ authors:
16
16
  autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
- date: 2020-05-01 00:00:00.000000000 Z
19
+ date: 2020-06-09 00:00:00.000000000 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: mocha
22
+ name: em-synchrony
23
23
  requirement: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
@@ -47,7 +47,7 @@ dependencies:
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  - !ruby/object:Gem::Dependency
50
- name: em-synchrony
50
+ name: mocha
51
51
  requirement: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - ">="