redis-client 0.23.2 → 0.25.0

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: a3aa8079ed55ab823901c58ee7fc725142ac9f2a964a7db9df9b6eaa8bf3b668
4
- data.tar.gz: 59127fed6458c327bd964a02e7e53de5172ba17eef7fc79b5dcae4a9cf339d6b
3
+ metadata.gz: 51d39972977cecb9d366e8475e937bf4e715c1b23dc79226ff357c8593974874
4
+ data.tar.gz: 2e8520f5c0b4f1325860bb155b1f203f6d5d950b3ead02a8f4a14219b4575b7e
5
5
  SHA512:
6
- metadata.gz: e0cb0139b70d63b59379364699b0ff4a883df931cd8ee60248dd5db23c20c789e752904babce6d48ecd215ef12eae8783c007b85aff1c6cb84057431d3cb1d1e
7
- data.tar.gz: 8fe7a3923239ca5143ac01d1b92e724d6ad3001cdb477032e7ed182358c16b0f38037f2f92e2e0b0f329c97967b477df65a041eace290605734d73dfcc7ab050
6
+ metadata.gz: 3c9a7e554039d54e10f4ea5fdb13c586a15f008b81fe4bb923f6b79f2953d70506ce2537f4932f932f716ab2b40aefae1899d1ade3ca08e198718c7878246c47
7
+ data.tar.gz: 304bf6766229b85ee85fb309b22680e431734054e63b02c5d1ae30bfb0a6e6521735832cbf6d9621916ddc6f41667b6555b7178c3670f999b8471d2a3c798cb9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Unreleased
2
2
 
3
+ # 0.25.0
4
+
5
+ - Fix `hiredis-client` compilation with GCC 15.
6
+ - Fix `hiredis-client` from a work directory with spaces.
7
+ - Add `CommandError#code`.
8
+ - Add `RedisClient::NoScriptError` for `EVALSHA`.
9
+
10
+ # 0.24.0
11
+
12
+ - Allow `sentinel_password` to be provided as a `Proc`.
13
+ - Ensure `Config#inspect` and `Config#to_s` do not display stored passwords.
14
+
3
15
  # 0.23.2
4
16
 
5
17
  - Fix retry logic not to attempt to retry on an open circuit breaker. Fix #227.
@@ -75,6 +87,7 @@
75
87
  - Discard sockets rather than explictly close them when a fork is detected. #126.
76
88
  - Allow to configure sentinel client via url. #117.
77
89
  - Fix sentinel to preverse the auth/password when refreshing the sentinel list. #107.
90
+ - Added `RedisClient#measure_round_trip_delay` method. #113.
78
91
 
79
92
  # 0.14.1
80
93
 
@@ -40,7 +40,7 @@ class RedisClient
40
40
  circuit_breaker: nil
41
41
  )
42
42
  @username = username
43
- @password = password
43
+ @password = password && !password.respond_to?(:call) ? ->(_) { password } : password
44
44
  @db = begin
45
45
  Integer(db || DEFAULT_DB)
46
46
  rescue ArgumentError
@@ -70,7 +70,6 @@ class RedisClient
70
70
 
71
71
  reconnect_attempts = Array.new(reconnect_attempts, 0).freeze if reconnect_attempts.is_a?(Integer)
72
72
  @reconnect_attempts = reconnect_attempts
73
- @connection_prelude = (build_connection_prelude unless @password.respond_to?(:call))
74
73
 
75
74
  circuit_breaker = CircuitBreaker.new(**circuit_breaker) if circuit_breaker.is_a?(Hash)
76
75
  if @circuit_breaker = circuit_breaker
@@ -88,19 +87,36 @@ class RedisClient
88
87
  end
89
88
 
90
89
  def connection_prelude
91
- if @password.respond_to?(:call)
92
- build_connection_prelude
93
- else
94
- @connection_prelude
90
+ prelude = []
91
+ pass = password
92
+ if protocol == 3
93
+ prelude << if pass
94
+ ["HELLO", "3", "AUTH", username, pass]
95
+ else
96
+ ["HELLO", "3"]
97
+ end
98
+ elsif pass
99
+ prelude << if @username && !@username.empty?
100
+ ["AUTH", @username, pass]
101
+ else
102
+ ["AUTH", pass]
103
+ end
95
104
  end
105
+
106
+ if @db && @db != 0
107
+ prelude << ["SELECT", @db.to_s]
108
+ end
109
+
110
+ # Deep freeze all the strings and commands
111
+ prelude.map! do |commands|
112
+ commands = commands.map { |str| str.frozen? ? str : str.dup.freeze }
113
+ commands.freeze
114
+ end
115
+ prelude.freeze
96
116
  end
97
117
 
98
118
  def password
99
- if @password.respond_to?(:call)
100
- @password.call(username)
101
- else
102
- @password
103
- end
119
+ @password&.call(username)
104
120
  end
105
121
 
106
122
  def username
@@ -162,37 +178,6 @@ class RedisClient
162
178
  end
163
179
  url
164
180
  end
165
-
166
- private
167
-
168
- def build_connection_prelude
169
- prelude = []
170
- pass = password
171
- if protocol == 3
172
- prelude << if pass
173
- ["HELLO", "3", "AUTH", username, pass]
174
- else
175
- ["HELLO", "3"]
176
- end
177
- elsif pass
178
- prelude << if @username && !@username.empty?
179
- ["AUTH", @username, pass]
180
- else
181
- ["AUTH", pass]
182
- end
183
- end
184
-
185
- if @db && @db != 0
186
- prelude << ["SELECT", @db.to_s]
187
- end
188
-
189
- # Deep freeze all the strings and commands
190
- prelude.map! do |commands|
191
- commands = commands.map { |str| str.frozen? ? str : str.dup.freeze }
192
- commands.freeze
193
- end
194
- prelude.freeze
195
- end
196
181
  end
197
182
 
198
183
  include Common
@@ -38,9 +38,14 @@ class RedisClient
38
38
  end
39
39
 
40
40
  @to_list_of_hash = @to_hash = nil
41
+ password = if sentinel_password && !sentinel_password.respond_to?(:call)
42
+ ->(_) { sentinel_password }
43
+ else
44
+ sentinel_password
45
+ end
41
46
  @extra_config = {
42
47
  username: sentinel_username,
43
- password: sentinel_password,
48
+ password: password,
44
49
  db: nil,
45
50
  }
46
51
  if client_config[:protocol] == 2
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class RedisClient
4
- VERSION = "0.23.2"
4
+ VERSION = "0.25.0"
5
5
  end
data/lib/redis_client.rb CHANGED
@@ -130,8 +130,18 @@ class RedisClient
130
130
  end
131
131
  end
132
132
 
133
+ module HasCode
134
+ attr_reader :code
135
+
136
+ def initialize(message = nil, code = nil)
137
+ super(message)
138
+ @code = code
139
+ end
140
+ end
141
+
133
142
  class CommandError < Error
134
143
  include HasCommand
144
+ include HasCode
135
145
 
136
146
  class << self
137
147
  def parse(error_message)
@@ -144,7 +154,7 @@ class RedisClient
144
154
  end
145
155
  code ||= error_message.split(' ', 2).first
146
156
  klass = ERRORS.fetch(code, self)
147
- klass.new(error_message.strip)
157
+ klass.new(error_message.strip, code.freeze)
148
158
  end
149
159
  end
150
160
  end
@@ -153,12 +163,15 @@ class RedisClient
153
163
  PermissionError = Class.new(CommandError)
154
164
  WrongTypeError = Class.new(CommandError)
155
165
  OutOfMemoryError = Class.new(CommandError)
166
+ NoScriptError = Class.new(CommandError)
156
167
 
157
168
  ReadOnlyError = Class.new(ConnectionError)
158
169
  ReadOnlyError.include(HasCommand)
170
+ ReadOnlyError.include(HasCode)
159
171
 
160
172
  MasterDownError = Class.new(ConnectionError)
161
173
  MasterDownError.include(HasCommand)
174
+ MasterDownError.include(HasCode)
162
175
 
163
176
  CommandError::ERRORS = {
164
177
  "WRONGPASS" => AuthenticationError,
@@ -167,6 +180,7 @@ class RedisClient
167
180
  "MASTERDOWN" => MasterDownError,
168
181
  "WRONGTYPE" => WrongTypeError,
169
182
  "OOM" => OutOfMemoryError,
183
+ "NOSCRIPT" => NoScriptError,
170
184
  }.freeze
171
185
 
172
186
  class << self
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.23.2
4
+ version: 0.25.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean Boussier
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-16 00:00:00.000000000 Z
10
+ date: 2025-06-17 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: connection_pool