Skip to content

Commit 072236e

Browse files
author
Jon Calvert
committed
Remove the extraneous expire during create, since the subsequent persist 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.
1 parent 9c580db commit 072236e

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

lib/redis/semaphore.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def exists_or_create!
3636
if token == API_VERSION && @redis.get(version_key).nil?
3737
@redis.set(version_key, API_VERSION)
3838
end
39-
39+
set_expiration_if_necessary
4040
true
4141
end
4242
end
@@ -59,7 +59,6 @@ def delete!
5959
def lock(timeout = 0)
6060
exists_or_create!
6161
release_stale_locks! if check_staleness?
62-
6362
token_pair = @redis.blpop(available_key, timeout)
6463
return false if token_pair.nil?
6564

@@ -157,8 +156,6 @@ def simple_mutex(key_name, expires = nil)
157156
end
158157

159158
def create!
160-
@redis.expire(exists_key, 10)
161-
162159
@redis.multi do
163160
@redis.del(grabbed_key)
164161
@redis.del(available_key)
@@ -167,7 +164,6 @@ def create!
167164
end
168165
@redis.set(version_key, API_VERSION)
169166
@redis.persist(exists_key)
170-
171167
set_expiration_if_necessary
172168
end
173169
end

0 commit comments

Comments
 (0)