Module: RedisQueuedLocks::Acquirer::LockInfo Private
- Defined in:
- lib/redis_queued_locks/acquirer/lock_info.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Class Method Summary collapse
-
.lock_info(redis_client, lock_name) ⇒ Hash<String,String|Numeric>, NilClass
private
rubocop:disable Metrics/MethodLength.
Class Method Details
.lock_info(redis_client, lock_name) ⇒ Hash<String,String|Numeric>, NilClass
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
rubocop:disable Metrics/MethodLength
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/redis_queued_locks/acquirer/lock_info.rb', line 30 def lock_info(redis_client, lock_name) lock_key = RedisQueuedLocks::Resource.prepare_lock_key(lock_name) result = redis_client.pipelined do |pipeline| pipeline.call('HGETALL', lock_key) pipeline.call('PTTL', lock_key) end if result == nil # NOTE: # - nil result means that during transaction invocation the lock is changed (CAS): # - lock is expired; # - lock is released; # - lock is expired + re-obtained; nil else # NOTE: the result of MULTI-command is an array of results of each internal command # - result[0] (HGETALL) (Hash<String,String>) # => (will be mutated further with different value types) # - result[1] (PTTL) (Integer) # => (without any mutation, integer is atomic) # @type var result: [Hash[String,String|Float|Integer],Integer] hget_cmd_res = result[0] pttl_cmd_res = result[1] if hget_cmd_res == {} || pttl_cmd_res == -2 # NOTE: key does not exist nil else hget_cmd_res.tap do |lock_data| lock_data['lock_key'] = lock_key lock_data['ts'] = Float(lock_data['ts']) lock_data['ini_ttl'] = Integer(lock_data['ini_ttl']) lock_data['rem_ttl'] = ((pttl_cmd_res == -1) ? Float::INFINITY : pttl_cmd_res) lock_data['spc_cnt'] = Integer(lock_data['spc_cnt']) if lock_data['spc_cnt'] lock_data['l_spc_ts'] = Float(lock_data['l_spc_ts']) if lock_data['l_spc_ts'] lock_data['spc_ext_ttl'] = Integer(lock_data['spc_ext_ttl']) if lock_data['spc_ext_ttl'] lock_data['l_spc_ext_ini_ttl'] = Integer(lock_data['l_spc_ext_ini_ttl']) if lock_data.key?('l_spc_ext_ini_ttl') lock_data['l_spc_ext_ts'] = Float(lock_data['l_spc_ext_ts']) if lock_data['l_spc_ext_ts'] end end end end |