mirror of
https://github.com/dkam/suo.git
synced 2025-01-29 07:42:43 +00:00
adds lock ttl and lock_release_removes_key
This commit is contained in:
@@ -5,7 +5,9 @@ module Suo
|
||||
acquisition_timeout: 0.1,
|
||||
acquisition_delay: 0.01,
|
||||
stale_lock_expiration: 3600,
|
||||
resources: 1
|
||||
resources: 1,
|
||||
lock_release_removes_key: false,
|
||||
ttl: nil,
|
||||
}.freeze
|
||||
|
||||
BLANK_STR = "".freeze
|
||||
@@ -81,8 +83,13 @@ 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
|
||||
end
|
||||
rescue LockClientError => _ # rubocop:disable Lint/HandleExceptions
|
||||
# ignore - assume success due to optimistic locking
|
||||
end
|
||||
|
||||
@@ -17,8 +17,12 @@ module Suo
|
||||
end
|
||||
|
||||
def set(newval, cas)
|
||||
if @options[:ttl]
|
||||
@client.set_cas(@key, newval, cas, {ttl: @options[:ttl]})
|
||||
else
|
||||
@client.set_cas(@key, newval, cas)
|
||||
end
|
||||
end
|
||||
|
||||
def initial_set(val = BLANK_STR)
|
||||
@client.set(@key, val)
|
||||
|
||||
@@ -20,8 +20,12 @@ module Suo
|
||||
|
||||
def set(newval, _)
|
||||
ret = @client.multi do |multi|
|
||||
if @options[:ttl]
|
||||
multi.setex(@key, @options[:ttl], newval)
|
||||
else
|
||||
multi.set(@key, newval)
|
||||
end
|
||||
end
|
||||
|
||||
ret && ret[0] == OK_STR
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user