Skip to content

Commit 99a24b2

Browse files
committed
chore: note it is safe to auto-reconnect
1 parent 983ceff commit 99a24b2

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Redlock works with Redis versions 6.0 or later.
1919

2020
Redlock >= 2.0 only works with `RedisClient` instance.
2121

22+
If you'd like to enable auto-reconnect attempts like in Redis 5,
23+
be sure to instantiate a RedisClient with `reconnect_attempts: 1`.
24+
2225
## Installation
2326

2427
Add this line to your application's Gemfile:

lib/redlock/client.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,17 @@ def initialize(connection)
169169
def lock(resource, val, ttl, allow_new_lock)
170170
recover_from_script_flush do
171171
@redis.with { |conn|
172-
conn.call('EVALSHA', Scripts::LOCK_SCRIPT_SHA, 1, resource, val, ttl, allow_new_lock)
172+
# NOTE: is not idempotent and unsafe to retry
173+
conn.call_once('EVALSHA', Scripts::LOCK_SCRIPT_SHA, 1, resource, val, ttl, allow_new_lock)
173174
}
174175
end
175176
end
176177

177178
def unlock(resource, val)
178179
recover_from_script_flush do
179180
@redis.with { |conn|
180-
conn.call('EVALSHA', Scripts::UNLOCK_SCRIPT_SHA, 1, resource, val)
181+
# NOTE: is not idempotent and unsafe to retry
182+
conn.call_once('EVALSHA', Scripts::UNLOCK_SCRIPT_SHA, 1, resource, val)
181183
}
182184
end
183185
rescue
@@ -187,6 +189,7 @@ def unlock(resource, val)
187189
def get_remaining_ttl(resource)
188190
recover_from_script_flush do
189191
@redis.with { |conn|
192+
# NOTE: is idempotent and safe to retry
190193
conn.call('EVALSHA', Scripts::PTTL_SCRIPT_SHA, 1, resource)
191194
}
192195
end
@@ -205,6 +208,7 @@ def load_scripts
205208

206209
@redis.with do |connnection|
207210
scripts.each do |script|
211+
# NOTE: is idempotent and safe to retry
208212
connnection.call('SCRIPT', 'LOAD', script)
209213
end
210214
end

0 commit comments

Comments
 (0)