From 7b04b73c54dd8c0738f8fd8f75ca336512b72d77 Mon Sep 17 00:00:00 2001 From: dany1468 Date: Sun, 8 Mar 2015 13:01:32 +0900 Subject: [PATCH 1/2] Add red spec --- spec/semaphore_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/semaphore_spec.rb b/spec/semaphore_spec.rb index 75fdbd3..45f5ff4 100644 --- a/spec/semaphore_spec.rb +++ b/spec/semaphore_spec.rb @@ -139,6 +139,15 @@ sleep 3.0 expect(@redis.keys.count).to eq(original_key_size) end + + it "expires keys after unlocking" do + original_key_size = @redis.keys.count + semaphore.lock do + # noop + end + sleep 3.0 + expect(@redis.keys.count).to eq(original_key_size) + end end describe "semaphore without staleness checking" do From b0bbfda39b4048fd130771cade651265bc1652ca Mon Sep 17 00:00:00 2001 From: dany1468 Date: Sun, 8 Mar 2015 13:29:18 +0900 Subject: [PATCH 2/2] Reset expiration when calling signal because available keys are not expired when using BLPOP --- lib/redis/semaphore.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/redis/semaphore.rb b/lib/redis/semaphore.rb index 22e1645..7ab1d77 100644 --- a/lib/redis/semaphore.rb +++ b/lib/redis/semaphore.rb @@ -37,7 +37,6 @@ def exists_or_create! @redis.set(version_key, API_VERSION) end - set_expiration_if_necessary true end end @@ -104,6 +103,8 @@ def signal(token = 1) @redis.multi do @redis.hdel grabbed_key, token @redis.lpush available_key, token + + set_expiration_if_necessary end end