Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. RedisStore.php

function RedisStore::putOffExpiration

Overrides PersistingStoreInterface::putOffExpiration

File

vendor/symfony/lock/Store/RedisStore.php, line 133

Class

RedisStore
RedisStore is a PersistingStoreInterface implementation using Redis as store engine.

Namespace

Symfony\Component\Lock\Store

Code

public function putOffExpiration(Key $key, float $ttl) : void {
    $script = '
            local key = KEYS[1]
            local uniqueToken = ARGV[2]
            local ttl = tonumber(ARGV[3])

            -- asserts the KEY is compatible with current version (old Symfony <5.2 BC)
            if redis.call("TYPE", key).ok == "string" then
                return false
            end

            ' . $this->getNowCode() . '

            -- lock already acquired acquired?
            if not redis.call("ZSCORE", key, uniqueToken) then
                return false
            end

            redis.call("ZADD", key, now + ttl, uniqueToken)
            -- if the lock is also a WRITE lock, increase the TTL
            if redis.call("ZSCORE", key, "__write__") then
                redis.call("ZADD", key, now + ttl, "__write__")
            end

            -- Extend the TTL of the key
            local maxExpiration = redis.call("ZREVRANGE", key, 0, 0, "WITHSCORES")[2]
            redis.call("PEXPIREAT", key, maxExpiration)

            return true
        ';
    $key->reduceLifetime($ttl);
    if (!$this->evaluate($script, (string) $key, [
        microtime(true),
        $this->getUniqueToken($key),
        (int) ceil($ttl * 1000),
    ])) {
        throw new LockConflictedException();
    }
    $this->checkNotExpired($key);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal