redis 4.1.4 → 4.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/README.md +8 -4
- data/lib/redis.rb +275 -237
- data/lib/redis/client.rb +66 -70
- data/lib/redis/cluster.rb +4 -0
- data/lib/redis/cluster/node.rb +3 -0
- data/lib/redis/cluster/option.rb +4 -1
- data/lib/redis/cluster/slot.rb +28 -14
- data/lib/redis/cluster/slot_loader.rb +2 -3
- data/lib/redis/connection.rb +1 -0
- data/lib/redis/connection/command_helper.rb +2 -2
- data/lib/redis/connection/hiredis.rb +3 -3
- data/lib/redis/connection/registry.rb +1 -1
- data/lib/redis/connection/ruby.rb +38 -61
- data/lib/redis/connection/synchrony.rb +8 -4
- data/lib/redis/distributed.rb +72 -50
- data/lib/redis/errors.rb +1 -0
- data/lib/redis/hash_ring.rb +14 -14
- data/lib/redis/pipeline.rb +6 -8
- data/lib/redis/subscribe.rb +10 -12
- data/lib/redis/version.rb +2 -1
- metadata +10 -5
data/lib/redis/errors.rb
CHANGED
data/lib/redis/hash_ring.rb
CHANGED
@@ -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.
|
50
|
+
return [nil, nil] if @ring.empty?
|
51
|
+
|
51
52
|
crc = Zlib.crc32(key)
|
52
53
|
idx = HashRing.binary_search(@sorted_keys, crc)
|
53
|
-
|
54
|
+
[@ring[@sorted_keys[idx]], idx]
|
54
55
|
end
|
55
56
|
|
56
57
|
def iter_nodes(key)
|
57
|
-
return [nil,nil] if @ring.
|
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
|
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
|
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
|
-
|
85
|
-
end
|
86
|
-
return upper
|
85
|
+
upper = ary.size - 1 if upper < 0
|
86
|
+
upper
|
87
87
|
end
|
88
88
|
end
|
89
89
|
end
|
data/lib/redis/pipeline.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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.
|
169
|
+
::Kernel.raise(@object) if @object.is_a?(::RuntimeError)
|
172
170
|
@object
|
173
171
|
end
|
174
172
|
|
data/lib/redis/subscribe.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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] =
|
60
|
+
hash[key] = ->(*_) {}
|
63
61
|
end
|
64
62
|
|
65
63
|
yield(self)
|
data/lib/redis/version.rb
CHANGED
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
|
+
version: 4.2.1
|
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-
|
19
|
+
date: 2020-06-11 00:00:00.000000000 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
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:
|
50
|
+
name: mocha
|
51
51
|
requirement: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - ">="
|
@@ -99,7 +99,12 @@ files:
|
|
99
99
|
homepage: https://github.com/redis/redis-rb
|
100
100
|
licenses:
|
101
101
|
- MIT
|
102
|
-
metadata:
|
102
|
+
metadata:
|
103
|
+
bug_tracker_uri: https://github.com/redis/redis-rb/issues
|
104
|
+
changelog_uri: https://github.com/redis/redis-rb/blob/master/CHANGELOG.md
|
105
|
+
documentation_uri: https://www.rubydoc.info/gems/redis/4.2.1
|
106
|
+
homepage_uri: https://github.com/redis/redis-rb
|
107
|
+
source_code_uri: https://github.com/redis/redis-rb/tree/v4.2.1
|
103
108
|
post_install_message:
|
104
109
|
rdoc_options: []
|
105
110
|
require_paths:
|