redlock 2.0.4 → 2.0.6

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: a0dee2cedbef9dc37a61a0708dc788287d3ab70b96bfd2561267ddd580e128f9
4
- data.tar.gz: 7e6292d1b22149c3c538c7f3bbd0285a9a7c51ef472d2ec22e99190927da5967
3
+ metadata.gz: 9dd90bf121367947d80385e0e24ec5aabe59e0e5452ee0d6dc7904fbd0a93fc7
4
+ data.tar.gz: d42662fb6a39139c47a9b0eff70efcdf5f59c067a1ab9d2205d0d881a94f2a73
5
5
  SHA512:
6
- metadata.gz: 4fccf4ff8a3c5647e828a71b6b982b67f5bc1cc702a88279752ce53fc88addc4f5ffaa657f4c7f5f5ca09bfb9ee27f2aee8f7551a9bfa655f176d99c98d76051
7
- data.tar.gz: ef9d3a5f10ec4b62b41ee890a69eb91ff16d92832ca75d82fb1387145330f979d8d01b614bf0893ad29669056f479a44f64278effcdbcc74150be2a4a2258f3d
6
+ metadata.gz: 3461e69ab931dd23bb5cf7a6d6d819a0fecf76eccb62a37e058e27a40780a5a9141f56b3d274ca94e4e51dd3edd9cd0c767ed8b3b2d6d6c33a5590d7b4531136
7
+ data.tar.gz: e29da6290a7192dc20ed68171c793a8b682a8849ecced7fab68d72a289f033661296846f4c908a82579a43bb5dbfa51cdd5392bef8ef728eaca5f4275d61addd
@@ -157,24 +157,19 @@ module Redlock
157
157
  private
158
158
 
159
159
  class RedisInstance
160
- module ConnectionPoolLike
161
- def with
162
- yield self
163
- end
164
- end
165
-
166
160
  def initialize(connection)
167
161
  @monitor = Monitor.new
168
162
 
169
- if connection.respond_to?(:with)
163
+ if connection.respond_to?(:call)
170
164
  @redis = connection
171
165
  else
172
166
  if connection.respond_to?(:client)
173
167
  @redis = connection
174
- else
168
+ elsif connection.respond_to?(:key?)
175
169
  @redis = initialize_client(connection)
170
+ else
171
+ @redis = connection
176
172
  end
177
- @redis.extend(ConnectionPoolLike)
178
173
  end
179
174
  end
180
175
 
@@ -202,7 +197,7 @@ module Redlock
202
197
  end
203
198
 
204
199
  def synchronize
205
- @monitor.synchronize { @redis.with { |connection| yield(connection) } }
200
+ @monitor.synchronize { @redis.then { |connection| yield(connection) } }
206
201
  end
207
202
 
208
203
  def lock(resource, val, ttl, allow_new_lock)
@@ -324,7 +319,8 @@ module Redlock
324
319
  @servers.each { |s| s.unlock(resource, value) }
325
320
 
326
321
  if errors.size >= @quorum
327
- raise LockAcquisitionError.new('Too many Redis errors prevented lock acquisition', errors)
322
+ err_msgs = errors.map { |e| "#{e.class}: #{e.message}" }.join("\n")
323
+ raise LockAcquisitionError.new("Too many Redis errors prevented lock acquisition:\n#{err_msgs}", errors)
328
324
  end
329
325
 
330
326
  false
@@ -1,3 +1,3 @@
1
1
  module Redlock
2
- VERSION = '2.0.4'
2
+ VERSION = '2.0.6'
3
3
  end
data/spec/client_spec.rb CHANGED
@@ -30,11 +30,7 @@ RSpec.describe Redlock::Client do
30
30
  let(:redis3_host) { ENV["REDIS3_HOST"] || "127.0.0.1" }
31
31
  let(:redis3_port) { ENV["REDIS3_PORT"] || "6379" }
32
32
  let(:unreachable_redis) {
33
- redis = RedisClient.new(url: 'redis://localhost:46864')
34
- def redis.with
35
- yield self
36
- end
37
- redis
33
+ RedisClient.new(url: 'redis://localhost:46864')
38
34
  }
39
35
 
40
36
  describe 'initialize' do
@@ -112,9 +108,19 @@ RSpec.describe Redlock::Client do
112
108
  it 'fails to acquire a lock if majority of Redis instances are not available' do
113
109
  redlock = Redlock::Client.new(servers_without_quorum)
114
110
 
111
+ expected_msg = <<~MSG
112
+ failed to acquire lock on 'Too many Redis errors prevented lock acquisition:
113
+ RedisClient::CannotConnectError: Connection refused - connect(2) for 127.0.0.1:46864
114
+ RedisClient::CannotConnectError: Connection refused - connect(2) for 127.0.0.1:46864'
115
+ MSG
116
+
115
117
  expect {
116
118
  redlock.lock(resource_key, ttl)
117
- }.to raise_error(Redlock::LockAcquisitionError)
119
+ }.to raise_error do |error|
120
+ expect(error).to be_a(Redlock::LockAcquisitionError)
121
+ expect(error.message).to eq(expected_msg.chomp)
122
+ expect(error.errors.size).to eq(2)
123
+ end
118
124
  end
119
125
  end
120
126
 
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
4
+ version: 2.0.6
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-20 00:00:00.000000000 Z
11
+ date: 2023-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis-client