adds lock ttl and lock_release_removes_key

This commit is contained in:
Ian Remillard
2018-09-28 12:43:52 -07:00
parent af1c476f08
commit fdb0b7f9d5
3 changed files with 19 additions and 4 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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