mirror of
https://github.com/dkam/suo.git
synced 2025-01-29 07:42:43 +00:00
move to expire only when all locks are released
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user