Skip to content

Commit

Permalink
Merge pull request #35 from dany1468/expire_available_keys_after_unlo…
Browse files Browse the repository at this point in the history
…cking

Expire available keys after unlocking
  • Loading branch information
dv committed Jun 21, 2015
2 parents 61d6f37 + b0bbfda commit c0cb437
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/redis/semaphore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def exists_or_create!
@redis.set(version_key, API_VERSION)
end

set_expiration_if_necessary
true
end
end
Expand Down Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions spec/semaphore_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c0cb437

Please sign in to comment.