redis-client 0.16.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 35ff65a4af6127cb60acff6a3d3b2d2e5e65ddeffc0e8e808b7dec90792697a6
4
- data.tar.gz: 854f82d7548c5462b53ae29a637dc208cdc70b3399b28d0c61f38e02f073e37e
3
+ metadata.gz: c8038f4b1f7316e16bd3561f43311334a9e69896e54a75b1a9666cb2718ba3b0
4
+ data.tar.gz: e37514256b44be8b0d5832c3d944c8d3be2a8228bff1fa05ac3a28347c6445ae
5
5
  SHA512:
6
- metadata.gz: 2c9e8e564662e86f4e1a24ca9528a5d909a096218eaf62bd7b58838402db390e7bec65d79a43aa89a2b98d22f9645ca7e412ae2db4010dc4131cbf2133d2666f
7
- data.tar.gz: c6400693a10e28e377bf52792ee54f41afb2b2c97ea49578a90eba767b6e3b6a7f37eaeaccf41a38a8222827f461f44aa0b1f75881084dc30a521e407508e277
6
+ metadata.gz: f02d99ca8c468cf38a4527817257169104d7f64cea5110c170d434d82b7f30cfea8338e0e746504d2d8c29866f81ef6cf4e81d014400ff364d5138d7653dfdc3
7
+ data.tar.gz: 2a66a02666e43b17c5007f2ae99c08f331cc46eb4645330b0f3df31fec39080ab779860bebcaa40add2beacc057d7a4ce586a7bc4453c50ddb0c4a10b677281f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Unreleased
2
2
 
3
+ # 0.17.0
4
+
5
+ - Adds `sentinel_username` and `sentinel_password` options for `RedisClient#sentinel`
6
+
3
7
  # 0.16.0
4
8
 
5
9
  - Add `RedisClient#disable_reconnection`.
@@ -71,7 +75,7 @@
71
75
 
72
76
  - Make the client resilient to `Timeout.timeout` or `Thread#kill` use (it still is very much discouraged to use either).
73
77
  Use of async interrupts could cause responses to be interleaved.
74
- - hiredis: handle commands returning a top-level `false` (no command does this today, but some extensions might).
78
+ - hiredis: handle commands returning a top-level `false` (no command does this today, but some extensions might).
75
79
  - Workaround a bug in Ruby 2.6 causing a crash if the `debug` gem is enabled when `redis-client` is being required. Fix: #48
76
80
 
77
81
  # 0.8.0
@@ -90,7 +94,7 @@
90
94
 
91
95
  - Raise a distinct `RedisClient::OutOfMemoryError`, for Redis `OOM` errors.
92
96
  - Fix the instrumentation API to be called even for authentication commands.
93
- - Fix `url:` configuration to accept a trailing slash.
97
+ - Fix `url:` configuration to accept a trailing slash.
94
98
 
95
99
  # 0.7.1
96
100
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- redis-client (0.16.0)
4
+ redis-client (0.17.0)
5
5
  connection_pool
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -128,6 +128,41 @@ but a few so that if one is down the client will try the next one. The client
128
128
  is able to remember the last Sentinel that was able to reply correctly and will
129
129
  use it for the next requests.
130
130
 
131
+ To [authenticate](https://redis.io/docs/management/sentinel/#configuring-sentinel-instances-with-authentication) Sentinel itself, you can specify the `sentinel_username` and `sentinel_password` options per instance. Exclude the `sentinel_username` option if you're using password-only authentication.
132
+
133
+ ```ruby
134
+ SENTINELS = [{ host: '127.0.0.1', port: 26380},
135
+ { host: '127.0.0.1', port: 26381}]
136
+
137
+ redis_config = RedisClient.sentinel(name: 'mymaster', sentinel_username: 'appuser', sentinel_password: 'mysecret', sentinels: SENTINELS, role: :master)
138
+ ```
139
+
140
+ If you specify a username and/or password at the top level for your main Redis instance, Sentinel *will not* using thouse credentials
141
+
142
+ ```ruby
143
+ # Use 'mysecret' to authenticate against the mymaster instance, but skip authentication for the sentinels:
144
+ SENTINELS = [{ host: '127.0.0.1', port: 26380 },
145
+ { host: '127.0.0.1', port: 26381 }]
146
+
147
+ redis_config = RedisClient.sentinel(name: 'mymaster', sentinels: SENTINELS, role: :master, password: 'mysecret')
148
+ ```
149
+
150
+ So you have to provide Sentinel credential and Redis explictly even they are the same
151
+
152
+ ```ruby
153
+ # Use 'mysecret' to authenticate against the mymaster instance and sentinel
154
+ SENTINELS = [{ host: '127.0.0.1', port: 26380 },
155
+ { host: '127.0.0.1', port: 26381 }]
156
+
157
+ redis_config = RedisClient.sentinel(name: 'mymaster', sentinels: SENTINELS, role: :master, password: 'mysecret', sentinel_password: 'mysecret')
158
+ ```
159
+
160
+ Also the `name`, `password`, `username` and `db` for Redis instance can be passed as an url:
161
+
162
+ ```ruby
163
+ redis_config = RedisClient.sentinel(url: "redis://appuser:mysecret@mymaster/10", sentinels: SENTINELS, role: :master)
164
+ ```
165
+
131
166
  ### Type support
132
167
 
133
168
  Only a select few Ruby types are supported as arguments beside strings.
@@ -159,21 +159,23 @@ class RedisClient
159
159
  host: nil,
160
160
  port: nil,
161
161
  path: nil,
162
+ username: nil,
163
+ password: nil,
162
164
  **kwargs
163
165
  )
164
166
  if url
165
167
  url_config = URLConfig.new(url)
166
168
  kwargs = {
167
169
  ssl: url_config.ssl?,
168
- username: url_config.username,
169
- password: url_config.password,
170
170
  db: url_config.db,
171
171
  }.compact.merge(kwargs)
172
172
  host ||= url_config.host
173
173
  port ||= url_config.port
174
+ username ||= url_config.username
175
+ password ||= url_config.password
174
176
  end
175
177
 
176
- super(**kwargs)
178
+ super(username: username, password: password, **kwargs)
177
179
 
178
180
  @host = host || DEFAULT_HOST
179
181
  @port = Integer(port || DEFAULT_PORT)
@@ -9,7 +9,15 @@ class RedisClient
9
9
 
10
10
  attr_reader :name
11
11
 
12
- def initialize(sentinels:, role: :master, name: nil, url: nil, **client_config)
12
+ def initialize(
13
+ sentinels:,
14
+ sentinel_password: nil,
15
+ sentinel_username: nil,
16
+ role: :master,
17
+ name: nil,
18
+ url: nil,
19
+ **client_config
20
+ )
13
21
  unless %i(master replica slave).include?(role.to_sym)
14
22
  raise ArgumentError, "Expected role to be either :master or :replica, got: #{role.inspect}"
15
23
  end
@@ -30,7 +38,11 @@ class RedisClient
30
38
  end
31
39
 
32
40
  @to_list_of_hash = @to_hash = nil
33
- @extra_config = {}
41
+ @extra_config = {
42
+ username: sentinel_username,
43
+ password: sentinel_password,
44
+ db: nil,
45
+ }
34
46
  if client_config[:protocol] == 2
35
47
  @extra_config[:protocol] = client_config[:protocol]
36
48
  @to_list_of_hash = lambda do |may_be_a_list|
@@ -106,9 +118,9 @@ class RedisClient
106
118
  sentinels.map do |sentinel|
107
119
  case sentinel
108
120
  when String
109
- Config.new(**@client_config, **@extra_config, url: sentinel, db: nil)
121
+ Config.new(**@client_config, **@extra_config, url: sentinel)
110
122
  else
111
- Config.new(**@client_config, **@extra_config, **sentinel, db: nil)
123
+ Config.new(**@client_config, **@extra_config, **sentinel)
112
124
  end
113
125
  end
114
126
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class RedisClient
4
- VERSION = "0.16.0"
4
+ VERSION = "0.17.0"
5
5
  end
data/lib/redis_client.rb CHANGED
@@ -175,6 +175,10 @@ class RedisClient
175
175
  "#<#{self.class.name} #{config.server_url}#{id_string}>"
176
176
  end
177
177
 
178
+ def server_url
179
+ config.server_url
180
+ end
181
+
178
182
  def size
179
183
  1
180
184
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean Boussier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-17 00:00:00.000000000 Z
11
+ date: 2023-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: connection_pool