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_timeout: 0.1,
|
||||||
acquisition_delay: 0.01,
|
acquisition_delay: 0.01,
|
||||||
stale_lock_expiration: 3600,
|
stale_lock_expiration: 3600,
|
||||||
resources: 1
|
resources: 1,
|
||||||
|
lock_release_removes_key: false,
|
||||||
|
ttl: nil,
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
BLANK_STR = "".freeze
|
BLANK_STR = "".freeze
|
||||||
@@ -81,7 +83,12 @@ module Suo
|
|||||||
acquisition_lock = remove_lock(cleared_locks, token)
|
acquisition_lock = remove_lock(cleared_locks, token)
|
||||||
|
|
||||||
break unless acquisition_lock
|
break unless acquisition_lock
|
||||||
break if set(serialize_locks(cleared_locks), cas)
|
|
||||||
|
if @options[:lock_release_removes_key] && cleared_locks.empty?
|
||||||
|
break if clear
|
||||||
|
else
|
||||||
|
break if set(serialize_locks(cleared_locks), cas)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
rescue LockClientError => _ # rubocop:disable Lint/HandleExceptions
|
rescue LockClientError => _ # rubocop:disable Lint/HandleExceptions
|
||||||
# ignore - assume success due to optimistic locking
|
# ignore - assume success due to optimistic locking
|
||||||
|
|||||||
@@ -17,7 +17,11 @@ module Suo
|
|||||||
end
|
end
|
||||||
|
|
||||||
def set(newval, cas)
|
def set(newval, cas)
|
||||||
@client.set_cas(@key, newval, cas)
|
if @options[:ttl]
|
||||||
|
@client.set_cas(@key, newval, cas, {ttl: @options[:ttl]})
|
||||||
|
else
|
||||||
|
@client.set_cas(@key, newval, cas)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def initial_set(val = BLANK_STR)
|
def initial_set(val = BLANK_STR)
|
||||||
|
|||||||
@@ -20,7 +20,11 @@ module Suo
|
|||||||
|
|
||||||
def set(newval, _)
|
def set(newval, _)
|
||||||
ret = @client.multi do |multi|
|
ret = @client.multi do |multi|
|
||||||
multi.set(@key, newval)
|
if @options[:ttl]
|
||||||
|
multi.setex(@key, @options[:ttl], newval)
|
||||||
|
else
|
||||||
|
multi.set(@key, newval)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ret && ret[0] == OK_STR
|
ret && ret[0] == OK_STR
|
||||||
|
|||||||
Reference in New Issue
Block a user