Skip to content

Commit

Permalink
Remove the extraneous expire during create, since the subsequent pers…
Browse files Browse the repository at this point in the history
…ist will obviate it anyway and since keys can expire during a MULTI transaction anyway. Return the removed statement where we always reset the key expiration prior to attempting to obtain a lock. This prevents the orphaned EXISTS key that never expires.
  • Loading branch information
Jon Calvert committed Jan 5, 2016
1 parent 9c580db commit 072236e
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions lib/redis/semaphore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def exists_or_create!
if token == API_VERSION && @redis.get(version_key).nil?
@redis.set(version_key, API_VERSION)
end

set_expiration_if_necessary
true
end
end
Expand All @@ -59,7 +59,6 @@ def delete!
def lock(timeout = 0)
exists_or_create!
release_stale_locks! if check_staleness?

token_pair = @redis.blpop(available_key, timeout)
return false if token_pair.nil?

Expand Down Expand Up @@ -157,8 +156,6 @@ def simple_mutex(key_name, expires = nil)
end

def create!
@redis.expire(exists_key, 10)

@redis.multi do
@redis.del(grabbed_key)
@redis.del(available_key)
Expand All @@ -167,7 +164,6 @@ def create!
end
@redis.set(version_key, API_VERSION)
@redis.persist(exists_key)

set_expiration_if_necessary
end
end
Expand Down

0 comments on commit 072236e

Please sign in to comment.