redis-client 0.26.0 → 0.26.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 +5 -0
- data/lib/redis_client/config.rb +3 -1
- data/lib/redis_client/connection_mixin.rb +8 -3
- data/lib/redis_client/ruby_connection.rb +8 -6
- data/lib/redis_client/sentinel_config.rb +4 -0
- data/lib/redis_client/version.rb +1 -1
- data/lib/redis_client.rb +23 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 532a6809e653318f469cf8aa5d3ed07498dd15b0557cea4449acde840f1c45ab
|
4
|
+
data.tar.gz: 8fef3135440099474344a957096db4ec1cc0d058e7e7ed80227282b37752ffd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9a13cf5d2bed374fec9ad8d4cf92e2c3dda1b4aea9ea03180144b83ac7115daf4e5252c5c78b3dfbc4cf69eba7c0a79d5cc021a608d544d982c7165e2d77f18
|
7
|
+
data.tar.gz: 21c1b9828143c1edaba52f5359f15ac887ef8070fe3948ec893a63ad3800ba4612379985673beaa39dc6143fa0c39f18f7e1dab20beded463b748c752d8627aa
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Unreleased
|
2
2
|
|
3
|
+
# 0.26.1
|
4
|
+
|
5
|
+
- Fix a few corner cases where `RedisClient::Error#final?` was innacurate.
|
6
|
+
- hiredis-client: Properly reconnect to the new leader after a sentinel failover.
|
7
|
+
|
3
8
|
# 0.26.0
|
4
9
|
|
5
10
|
- Add `RedisClient::Error#final?` and `#retriable?` to allow middleware to filter out non-final errors.
|
data/lib/redis_client/config.rb
CHANGED
@@ -186,7 +186,7 @@ class RedisClient
|
|
186
186
|
|
187
187
|
include Common
|
188
188
|
|
189
|
-
attr_reader :host, :port, :path
|
189
|
+
attr_reader :host, :port, :path, :server_key
|
190
190
|
|
191
191
|
def initialize(
|
192
192
|
url: nil,
|
@@ -220,6 +220,8 @@ class RedisClient
|
|
220
220
|
@host = host || DEFAULT_HOST
|
221
221
|
@port = Integer(port || DEFAULT_PORT)
|
222
222
|
end
|
223
|
+
|
224
|
+
@server_key = [@path, @host, @port].freeze
|
223
225
|
end
|
224
226
|
end
|
225
227
|
end
|
@@ -3,10 +3,13 @@
|
|
3
3
|
class RedisClient
|
4
4
|
module ConnectionMixin
|
5
5
|
attr_accessor :retry_attempt
|
6
|
+
attr_reader :config
|
6
7
|
|
7
|
-
def initialize
|
8
|
+
def initialize(config)
|
8
9
|
@pending_reads = 0
|
9
10
|
@retry_attempt = nil
|
11
|
+
@config = config
|
12
|
+
@server_key = nil
|
10
13
|
end
|
11
14
|
|
12
15
|
def reconnect
|
@@ -20,7 +23,7 @@ class RedisClient
|
|
20
23
|
end
|
21
24
|
|
22
25
|
def revalidate
|
23
|
-
if @pending_reads > 0
|
26
|
+
if @pending_reads > 0 || @server_key != @config.server_key
|
24
27
|
close
|
25
28
|
false
|
26
29
|
else
|
@@ -89,7 +92,9 @@ class RedisClient
|
|
89
92
|
end
|
90
93
|
|
91
94
|
def protocol_error(message)
|
92
|
-
ProtocolError.with_config(message, config)
|
95
|
+
error = ProtocolError.with_config(message, config)
|
96
|
+
error._set_retry_attempt(@retry_attempt)
|
97
|
+
error
|
93
98
|
end
|
94
99
|
|
95
100
|
def connection_error(message)
|
@@ -40,11 +40,8 @@ class RedisClient
|
|
40
40
|
|
41
41
|
SUPPORTS_RESOLV_TIMEOUT = Socket.method(:tcp).parameters.any? { |p| p.last == :resolv_timeout }
|
42
42
|
|
43
|
-
attr_reader :config
|
44
|
-
|
45
43
|
def initialize(config, connect_timeout:, read_timeout:, write_timeout:)
|
46
|
-
super()
|
47
|
-
@config = config
|
44
|
+
super(config)
|
48
45
|
@connect_timeout = connect_timeout
|
49
46
|
@read_timeout = read_timeout
|
50
47
|
@write_timeout = write_timeout
|
@@ -76,6 +73,10 @@ class RedisClient
|
|
76
73
|
@io.write(buffer)
|
77
74
|
rescue SystemCallError, IOError, OpenSSL::SSL::SSLError => error
|
78
75
|
raise connection_error(error.message)
|
76
|
+
rescue Error => error
|
77
|
+
error._set_config(config)
|
78
|
+
error._set_retry_attempt(@retry_attempt)
|
79
|
+
raise error
|
79
80
|
end
|
80
81
|
end
|
81
82
|
|
@@ -97,8 +98,8 @@ class RedisClient
|
|
97
98
|
else
|
98
99
|
@io.with_timeout(timeout) { RESP3.load(@io) }
|
99
100
|
end
|
100
|
-
rescue RedisClient::RESP3::
|
101
|
-
raise
|
101
|
+
rescue RedisClient::RESP3::Error => error
|
102
|
+
raise protocol_error(error.message)
|
102
103
|
rescue SystemCallError, IOError, OpenSSL::SSL::SSLError => error
|
103
104
|
raise connection_error(error.message)
|
104
105
|
end
|
@@ -112,6 +113,7 @@ class RedisClient
|
|
112
113
|
private
|
113
114
|
|
114
115
|
def connect
|
116
|
+
@server_key = @config.server_key
|
115
117
|
socket = if @config.path
|
116
118
|
UNIXSocket.new(@config.path)
|
117
119
|
else
|
data/lib/redis_client/version.rb
CHANGED
data/lib/redis_client.rb
CHANGED
@@ -117,6 +117,23 @@ class RedisClient
|
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
|
+
module Final
|
121
|
+
def _set_retry_attempt(_retry_attempt)
|
122
|
+
end
|
123
|
+
|
124
|
+
def retry_attempt
|
125
|
+
0
|
126
|
+
end
|
127
|
+
|
128
|
+
def retriable?
|
129
|
+
false
|
130
|
+
end
|
131
|
+
|
132
|
+
def final?
|
133
|
+
true
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
120
137
|
class Error < StandardError
|
121
138
|
include HasConfig
|
122
139
|
include Retriable
|
@@ -161,6 +178,7 @@ class RedisClient
|
|
161
178
|
class CommandError < Error
|
162
179
|
include HasCommand
|
163
180
|
include HasCode
|
181
|
+
include Final
|
164
182
|
|
165
183
|
class << self
|
166
184
|
def parse(error_message)
|
@@ -231,6 +249,7 @@ class RedisClient
|
|
231
249
|
@middlewares = config.middlewares_stack.new(self)
|
232
250
|
@raw_connection = nil
|
233
251
|
@disable_reconnection = false
|
252
|
+
@retry_attempt = nil
|
234
253
|
end
|
235
254
|
|
236
255
|
def inspect
|
@@ -736,8 +755,8 @@ class RedisClient
|
|
736
755
|
connection = nil
|
737
756
|
preferred_error = nil
|
738
757
|
begin
|
758
|
+
@retry_attempt = config.retriable?(tries) ? tries : nil
|
739
759
|
connection = raw_connection
|
740
|
-
connection.retry_attempt = config.retriable?(tries) ? tries : nil
|
741
760
|
if block_given?
|
742
761
|
yield connection
|
743
762
|
else
|
@@ -780,13 +799,14 @@ class RedisClient
|
|
780
799
|
if @raw_connection.nil? || !@raw_connection.revalidate
|
781
800
|
connect
|
782
801
|
end
|
802
|
+
@raw_connection.retry_attempt = @retry_attempt
|
783
803
|
@raw_connection
|
784
804
|
end
|
785
805
|
|
786
806
|
def connect
|
787
807
|
@pid = PIDCache.pid
|
788
808
|
|
789
|
-
if @raw_connection
|
809
|
+
if @raw_connection&.revalidate
|
790
810
|
@middlewares.connect(config) do
|
791
811
|
@raw_connection.reconnect
|
792
812
|
end
|
@@ -800,6 +820,7 @@ class RedisClient
|
|
800
820
|
)
|
801
821
|
end
|
802
822
|
end
|
823
|
+
@raw_connection.retry_attempt = @retry_attempt
|
803
824
|
|
804
825
|
prelude = config.connection_prelude.dup
|
805
826
|
|