Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkamel committed Sep 21, 2024
1 parent 872214e commit 68a00ce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/redstream/lock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions spec/redstream/lock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 68a00ce

Please sign in to comment.