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

Breadcrumb

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

function RedisStore::getNowCode

4 calls to RedisStore::getNowCode()
RedisStore::exists in vendor/symfony/lock/Store/RedisStore.php
Returns whether or not the resource exists in the storage.
RedisStore::putOffExpiration in vendor/symfony/lock/Store/RedisStore.php
Extends the TTL of a resource.
RedisStore::save in vendor/symfony/lock/Store/RedisStore.php
Stores the resource if it's not locked by someone else.
RedisStore::saveRead in vendor/symfony/lock/Store/RedisStore.php
Stores the resource if it's not locked for reading by someone else.

File

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

Class

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

Namespace

Symfony\Component\Lock\Store

Code

private function getNowCode() : string {
    if (!isset($this->supportTime)) {
        // Redis < 5.0 does not support TIME (not deterministic) in script.
        // https://redis.io/commands/eval#replicating-commands-instead-of-scripts
        // This code asserts TIME can be use, otherwise will fallback to a timestamp generated by the PHP process.
        $script = '
                local now = redis.call("TIME")
                redis.call("SET", KEYS[1], "1", "PX", 1)

	            return 1
            ';
        try {
            $this->supportTime = 1 === $this->evaluate($script, 'symfony_check_support_time', []);
        } catch (LockStorageException $e) {
            if (!str_contains($e->getMessage(), 'commands not allowed after non deterministic') && !str_contains($e->getMessage(), 'is not allowed from script script')) {
                throw $e;
            }
            $this->supportTime = false;
        }
    }
    if ($this->supportTime) {
        return '
                local now = redis.call("TIME")
                now = now[1] * 1000 + math.floor(now[2] / 1000)
            ';
    }
    return '
            local now = tonumber(ARGV[1])
            now = math.floor(now * 1000)
        ';
}

API Navigation

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