lib/suo/client/redis.rb in suo-0.1.0 vs lib/suo/client/redis.rb in suo-0.1.1

- old
+ new

@@ -15,10 +15,15 @@ begin start = Time.now.to_f options[:retry_count].times do + if options[:retry_timeout] + now = Time.now.to_f + break if now - start > options[:retry_timeout] + end + client.watch(key) do begin val = client.get(key) locks = clear_expired_locks(deserialize_locks(val.to_s), options) @@ -39,19 +44,13 @@ end end break if acquisition_token - if options[:retry_timeout] - now = Time.now.to_f - break if now - start > options[:retry_timeout] - end - sleep(rand(options[:retry_delay] * 1000).to_f / 1000) end - rescue => boom - raise boom + rescue => _ raise Suo::Client::FailedToAcquireLock end acquisition_token end @@ -63,10 +62,15 @@ begin start = Time.now.to_f options[:retry_count].times do + if options[:retry_timeout] + now = Time.now.to_f + break if now - start > options[:retry_timeout] + end + client.watch(key) do begin val = client.get(key) locks = clear_expired_locks(deserialize_locks(val), options) @@ -85,15 +89,10 @@ end end break if refreshed - if options[:retry_timeout] - now = Time.now.to_f - break if now - start > options[:retry_timeout] - end - sleep(rand(options[:retry_delay] * 1000).to_f / 1000) end rescue => _ raise Suo::Client::FailedToAcquireLock end @@ -109,10 +108,15 @@ start = Time.now.to_f options[:retry_count].times do cleared = false + if options[:retry_timeout] + now = Time.now.to_f + break if now - start > options[:retry_timeout] + end + client.watch(key) do begin val = client.get(key) if val.nil? @@ -141,14 +145,9 @@ client.unwatch end end break if cleared - - if options[:retry_timeout] - now = Time.now.to_f - break if now - start > options[:retry_timeout] - end sleep(rand(options[:retry_delay] * 1000).to_f / 1000) end rescue => boom # rubocop:disable Lint/HandleExceptions # since it's optimistic locking - fine if we are unable to release