move to expire only when all locks are released

This commit is contained in:
Ian Remillard
2018-10-01 10:35:30 -07:00
parent 6be3a5bdda
commit 1022a6f9d3
4 changed files with 10 additions and 23 deletions

View File

@@ -6,8 +6,7 @@ module Suo
acquisition_delay: 0.01,
stale_lock_expiration: 3600,
resources: 1,
lock_release_removes_key: false,
ttl: nil,
ttl: 60,
}.freeze
BLANK_STR = "".freeze
@@ -66,7 +65,7 @@ module Suo
refresh_lock(cleared_locks, token)
break if set(serialize_locks(cleared_locks), cas)
break if set(serialize_locks(cleared_locks), cas, expire: cleared_locks.empty?)
end
end
@@ -83,12 +82,7 @@ module Suo
acquisition_lock = remove_lock(cleared_locks, token)
break unless acquisition_lock
if @options[:lock_release_removes_key] && cleared_locks.empty?
break if clear
else
break if set(serialize_locks(cleared_locks), cas)
end
break if set(serialize_locks(cleared_locks), cas, expire: cleared_locks.empty?)
end
rescue LockClientError => _ # rubocop:disable Lint/HandleExceptions
# ignore - assume success due to optimistic locking

View File

@@ -16,9 +16,9 @@ module Suo
@client.get_cas(@key)
end
def set(newval, cas)
if @options[:ttl]
@client.set_cas(@key, newval, cas, {ttl: @options[:ttl]})
def set(newval, cas, expire:)
if expire
@client.set_cas(@key, newval, cas, @options[:ttl])
else
@client.set_cas(@key, newval, cas)
end

View File

@@ -18,9 +18,9 @@ module Suo
[@client.get(@key), nil]
end
def set(newval, _)
def set(newval, _, expire:)
ret = @client.multi do |multi|
if @options[:ttl]
if expire
multi.setex(@key, @options[:ttl], newval)
else
multi.set(@key, newval)