redlock 2.0.3 → 2.0.4
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/README.md +17 -2
- data/lib/redlock/client.rb +12 -5
- data/lib/redlock/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0dee2cedbef9dc37a61a0708dc788287d3ab70b96bfd2561267ddd580e128f9
|
4
|
+
data.tar.gz: 7e6292d1b22149c3c538c7f3bbd0285a9a7c51ef472d2ec22e99190927da5967
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fccf4ff8a3c5647e828a71b6b982b67f5bc1cc702a88279752ce53fc88addc4f5ffaa657f4c7f5f5ca09bfb9ee27f2aee8f7551a9bfa655f176d99c98d76051
|
7
|
+
data.tar.gz: ef9d3a5f10ec4b62b41ee890a69eb91ff16d92832ca75d82fb1387145330f979d8d01b614bf0893ad29669056f479a44f64278effcdbcc74150be2a4a2258f3d
|
data/README.md
CHANGED
@@ -176,14 +176,29 @@ lock_manager.get_remaining_ttl_for_resource(resource)
|
|
176
176
|
|
177
177
|
## Redis client configuration
|
178
178
|
|
179
|
-
`Redlock::Client` expects URLs or Redis objects on initialization. Redis objects should be used for configuring the connection in more detail, i.e. setting username and password.
|
179
|
+
`Redlock::Client` expects URLs, or configurations or Redis objects on initialization. Redis objects should be used for configuring the connection in more detail, i.e. setting username and password.
|
180
180
|
|
181
181
|
```ruby
|
182
182
|
servers = [ 'redis://localhost:6379', RedisClient.new(:url => 'redis://someotherhost:6379') ]
|
183
183
|
redlock = Redlock::Client.new(servers)
|
184
184
|
```
|
185
185
|
|
186
|
-
|
186
|
+
To utilize `Redlock::Client` with sentinels you can pass an instance of `RedisClient` or just a configuration hash as part of the servers array during initialization.
|
187
|
+
|
188
|
+
```ruby
|
189
|
+
config = {
|
190
|
+
name: "mymaster",
|
191
|
+
sentinels: [
|
192
|
+
{ host: "127.0.0.1", port: 26380 },
|
193
|
+
{ host: "127.0.0.1", port: 26381 },
|
194
|
+
],
|
195
|
+
role: :master
|
196
|
+
}
|
197
|
+
client = RedisClient.sentinel(**config).new_client
|
198
|
+
servers = [ config, client ]
|
199
|
+
redlock = Redlock::Client.new(servers)
|
200
|
+
```
|
201
|
+
Redlock supports the same configuration hash as `RedisClient`.
|
187
202
|
|
188
203
|
## Redlock configuration
|
189
204
|
|
data/lib/redlock/client.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
+
require 'monitor'
|
1
2
|
require 'redis-client'
|
2
3
|
require 'securerandom'
|
3
4
|
|
4
5
|
module Redlock
|
5
6
|
include Scripts
|
6
7
|
|
7
|
-
class LockAcquisitionError <
|
8
|
+
class LockAcquisitionError < LockError
|
8
9
|
attr_reader :errors
|
9
10
|
|
10
11
|
def initialize(message, errors)
|
@@ -163,6 +164,8 @@ module Redlock
|
|
163
164
|
end
|
164
165
|
|
165
166
|
def initialize(connection)
|
167
|
+
@monitor = Monitor.new
|
168
|
+
|
166
169
|
if connection.respond_to?(:with)
|
167
170
|
@redis = connection
|
168
171
|
else
|
@@ -198,9 +201,13 @@ module Redlock
|
|
198
201
|
end
|
199
202
|
end
|
200
203
|
|
204
|
+
def synchronize
|
205
|
+
@monitor.synchronize { @redis.with { |connection| yield(connection) } }
|
206
|
+
end
|
207
|
+
|
201
208
|
def lock(resource, val, ttl, allow_new_lock)
|
202
209
|
recover_from_script_flush do
|
203
|
-
|
210
|
+
synchronize { |conn|
|
204
211
|
conn.call('EVALSHA', Scripts::LOCK_SCRIPT_SHA, 1, resource, val, ttl, allow_new_lock)
|
205
212
|
}
|
206
213
|
end
|
@@ -208,7 +215,7 @@ module Redlock
|
|
208
215
|
|
209
216
|
def unlock(resource, val)
|
210
217
|
recover_from_script_flush do
|
211
|
-
|
218
|
+
synchronize { |conn|
|
212
219
|
conn.call('EVALSHA', Scripts::UNLOCK_SCRIPT_SHA, 1, resource, val)
|
213
220
|
}
|
214
221
|
end
|
@@ -218,7 +225,7 @@ module Redlock
|
|
218
225
|
|
219
226
|
def get_remaining_ttl(resource)
|
220
227
|
recover_from_script_flush do
|
221
|
-
|
228
|
+
synchronize { |conn|
|
222
229
|
conn.call('EVALSHA', Scripts::PTTL_SCRIPT_SHA, 1, resource)
|
223
230
|
}
|
224
231
|
end
|
@@ -235,7 +242,7 @@ module Redlock
|
|
235
242
|
Scripts::PTTL_SCRIPT
|
236
243
|
]
|
237
244
|
|
238
|
-
|
245
|
+
synchronize do |connnection|
|
239
246
|
scripts.each do |script|
|
240
247
|
connnection.call('SCRIPT', 'LOAD', script)
|
241
248
|
end
|
data/lib/redlock/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redlock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leandro Moreira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-08-
|
11
|
+
date: 2023-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis-client
|