Sha256: b5ebe919b262a1fba117b553639086b54873c7b7dadfa67e113df9fae1d6ad79

Contents?: true

Size: 1.82 KB

Versions: 2

Compression:

Stored size: 1.82 KB

Contents

# frozen_string_literal: true

# @api private
# @since 1.0.0
module RedisQueuedLocks::Acquier::ExtendLockTTL
  # @return [String]
  #
  # @api private
  # @since 1.0.0
  EXTEND_LOCK_PTTL = <<~LUA_SCRIPT.strip.tr("\n", '').freeze
    local new_lock_pttl = redis.call("PTTL", KEYS[1]) + ARGV[1];
    return redis.call("PEXPIRE", KEYS[1], new_lock_pttl);
  LUA_SCRIPT

  class << self
    # @param redis_client [RedisClient]
    # @param lock_name [String]
    # @param milliseconds [Integer]
    # @param logger [::Logger,#debug]
    # @param instrumenter [#notify]
    # @param instrument [NilClass,Any]
    # @param log_sampling_enabled [Boolean]
    # @param log_sampling_percent [Integer]
    # @param log_sampler [#sampling_happened?,Module<RedisQueuedLocks::Logging::Sampler>]
    # @param instr_sampling_enabled [Boolean]
    # @param instr_sampling_percent [Integer]
    # @param instr_sampler [#sampling_happened?,Module<RedisQueuedLocks::Instrument::Sampler>]
    # @return [Hash<Symbol,Boolean|Symbol>]
    #
    # @api private
    # @since 1.0.0
    # @version 1.6.0
    def extend_lock_ttl(
      redis_client,
      lock_name,
      milliseconds,
      logger,
      instrumenter,
      instrument,
      log_sampling_enabled,
      log_sampling_percent,
      log_sampler,
      instr_sampling_enabled,
      instr_sampling_percent,
      instr_sampler
    )
      lock_key = RedisQueuedLocks::Resource.prepare_lock_key(lock_name)

      # NOTE: EVAL signature -> <lua script>, (number of keys), *(keys), *(arguments)
      result = redis_client.call('EVAL', EXTEND_LOCK_PTTL, 1, lock_key, milliseconds)
      # TODO: upload scripts to the redis

      if result == 1
        RedisQueuedLocks::Data[ok: true, result: :ttl_extended]
      else
        RedisQueuedLocks::Data[ok: false, result: :async_expire_or_no_lock]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
redis_queued_locks-1.8.0 lib/redis_queued_locks/acquier/extend_lock_ttl.rb
redis_queued_locks-1.7.0 lib/redis_queued_locks/acquier/extend_lock_ttl.rb