From 68a00ce5f7d8c2d0cef535f74ffd0fc93961c938 Mon Sep 17 00:00:00 2001 From: Benjamin Vetter Date: Sat, 21 Sep 2024 18:20:14 +0200 Subject: [PATCH] Fix --- lib/redstream/lock.rb | 2 +- spec/redstream/lock_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/redstream/lock.rb b/lib/redstream/lock.rb index 90e9b37..85a356b 100644 --- a/lib/redstream/lock.rb +++ b/lib/redstream/lock.rb @@ -108,7 +108,7 @@ def release_lock @release_lock_script = <<~SCRIPT local lock_key_name, id = ARGV[1], ARGV[2] - local cur = redis.call('del', lock_key_name) + local cur = redis.call('get', lock_key_name) if cur and cur == id then redis.call('del', lock_key_name) diff --git a/spec/redstream/lock_spec.rb b/spec/redstream/lock_spec.rb index f25fd9f..b89268e 100644 --- a/spec/redstream/lock_spec.rb +++ b/spec/redstream/lock_spec.rb @@ -76,6 +76,16 @@ expect(redis.llen("#{Redstream.lock_key_name("lock")}.notify")).to eq(1) end + it "does not release the lock when the lock is already taken again" do + lock = Redstream::Lock.new(name: "lock") + + lock.acquire do + redis.set(Redstream.lock_key_name("lock"), "other") + end + + expect(redis.get(Redstream.lock_key_name("lock"))).to eq("other") + end + it "acquires the lock as soon as it gets released" do time = nil