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

Breadcrumb

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

function RedisStore::evaluate

6 calls to RedisStore::evaluate()
RedisStore::delete in vendor/symfony/lock/Store/RedisStore.php
Removes a resource from the storage.
RedisStore::exists in vendor/symfony/lock/Store/RedisStore.php
Returns whether or not the resource exists in the storage.
RedisStore::getNowCode in vendor/symfony/lock/Store/RedisStore.php
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.

... See full list

File

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

Class

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

Namespace

Symfony\Component\Lock\Store

Code

private function evaluate(string $script, string $resource, array $args) : mixed {
    $scriptSha = sha1($script);
    if ($this->redis instanceof \Redis || $this->redis instanceof Relay || $this->redis instanceof \RedisCluster) {
        $this->redis
            ->clearLastError();
        $result = $this->redis
            ->evalSha($scriptSha, array_merge([
            $resource,
        ], $args), 1);
        if (self::NO_SCRIPT_ERROR_MESSAGE === ($err = $this->redis
            ->getLastError())) {
            $this->redis
                ->clearLastError();
            if ($this->redis instanceof \RedisCluster) {
                foreach ($this->redis
                    ->_masters() as $master) {
                    $this->redis
                        ->script($master, 'LOAD', $script);
                }
            }
            else {
                $this->redis
                    ->script('LOAD', $script);
            }
            if (null !== ($err = $this->redis
                ->getLastError())) {
                throw new LockStorageException($err);
            }
            $result = $this->redis
                ->evalSha($scriptSha, array_merge([
                $resource,
            ], $args), 1);
            if (null !== ($err = $this->redis
                ->getLastError())) {
                throw new LockStorageException($err);
            }
        }
        return $result;
    }
    if ($this->redis instanceof \RedisArray) {
        $client = $this->redis
            ->_instance($this->redis
            ->_target($resource));
        $client->clearLastError();
        $result = $client->evalSha($scriptSha, array_merge([
            $resource,
        ], $args), 1);
        if (self::NO_SCRIPT_ERROR_MESSAGE === ($err = $client->getLastError())) {
            $client->clearLastError();
            $client->script('LOAD', $script);
            if (null !== ($err = $client->getLastError())) {
                throw new LockStorageException($err);
            }
            $result = $client->evalSha($scriptSha, array_merge([
                $resource,
            ], $args), 1);
            if (null !== ($err = $client->getLastError())) {
                throw new LockStorageException($err);
            }
        }
        return $result;
    }
    \assert($this->redis instanceof \Predis\ClientInterface);
    try {
        return $this->redis
            ->evalSha($scriptSha, 1, $resource, ...$args);
    } catch (ServerException $e) {
        // Fallthrough only if we need to load the script
        if (self::NO_SCRIPT_ERROR_MESSAGE !== $e->getMessage()) {
            throw new LockStorageException($e->getMessage(), $e->getCode(), $e);
        }
    }
    try {
        $this->redis
            ->script('LOAD', $script);
    } catch (ServerException $e) {
        throw new LockStorageException($e->getMessage(), $e->getCode(), $e);
    }
    try {
        return $this->redis
            ->evalSha($scriptSha, 1, $resource, ...$args);
    } catch (ServerException $e) {
        throw new LockStorageException($e->getMessage(), $e->getCode(), $e);
    }
}

API Navigation

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