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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f265ac0d87bb764ab0e577f3ef0440b155de0ba2d88d44469167a634eebd03bb
4
- data.tar.gz: 6edcf258e079c1123587e2f670793bd64dd38ada6116c31ddf992a328f015ecd
3
+ metadata.gz: 532a6809e653318f469cf8aa5d3ed07498dd15b0557cea4449acde840f1c45ab
4
+ data.tar.gz: 8fef3135440099474344a957096db4ec1cc0d058e7e7ed80227282b37752ffd1
5
5
  SHA512:
6
- metadata.gz: dfd46c41eca304f6b438da604089e51719239c0e72a3658a464c1f769fa14b005415e105cc2765a98f3e708b41fa39073ed5d982539fa58a465f391c7f3d40fd
7
- data.tar.gz: 2b2180f10bf25af818729ccce4724d378a03cb009361fb76c5b704c0171ca19c66766878e375f5f4e483f1b604c3e5ff8ca29ffe7495aa15ca0b2c3f5a4c0b7e
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.
@@ -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::UnknownType => error
101
- raise RedisClient::ProtocolError.with_config(error.message, config)
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
@@ -82,6 +82,10 @@ class RedisClient
82
82
  end
83
83
  end
84
84
 
85
+ def server_key
86
+ config.server_key
87
+ end
88
+
85
89
  def host
86
90
  config.host
87
91
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class RedisClient
4
- VERSION = "0.26.0"
4
+ VERSION = "0.26.1"
5
5
  end
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.26.0
4
+ version: 0.26.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean Boussier