diff --git a/README.md b/README.md index 710d847..db57c18 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,9 @@ Redlock works with Redis versions 6.0 or later. Redlock >= 2.0 only works with `RedisClient` instance. +If you'd like to enable auto-reconnect attempts like in Redis 5, +be sure to instantiate a RedisClient with `reconnect_attempts: 1`. + ## Installation Add this line to your application's Gemfile: diff --git a/lib/redlock/client.rb b/lib/redlock/client.rb index f538eeb..5c66df7 100644 --- a/lib/redlock/client.rb +++ b/lib/redlock/client.rb @@ -169,6 +169,7 @@ def initialize(connection) def lock(resource, val, ttl, allow_new_lock) recover_from_script_flush do @redis.with { |conn| + # NOTE: is idempotent and safe to retry conn.call('EVALSHA', Scripts::LOCK_SCRIPT_SHA, 1, resource, val, ttl, allow_new_lock) } end @@ -177,6 +178,7 @@ def lock(resource, val, ttl, allow_new_lock) def unlock(resource, val) recover_from_script_flush do @redis.with { |conn| + # NOTE: is idempotent and safe to retry conn.call('EVALSHA', Scripts::UNLOCK_SCRIPT_SHA, 1, resource, val) } end @@ -187,6 +189,7 @@ def unlock(resource, val) def get_remaining_ttl(resource) recover_from_script_flush do @redis.with { |conn| + # NOTE: is idempotent and safe to retry conn.call('EVALSHA', Scripts::PTTL_SCRIPT_SHA, 1, resource) } end @@ -205,6 +208,7 @@ def load_scripts @redis.with do |connnection| scripts.each do |script| + # NOTE: is idempotent and safe to retry connnection.call('SCRIPT', 'LOAD', script) end end