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 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