InvalidTtlException example

$this->randomlyPrune();
        $this->checkNotExpired($key);
    }

    /** * @return void */
    public function putOffExpiration(Key $key, float $ttl)
    {
        if ($ttl < 1) {
            throw new InvalidTtlException(sprintf('"%s()" expects a TTL greater or equals to 1 second. Got "%s".', __METHOD__, $ttl));
        }

        $key->reduceLifetime($ttl);

        $sql = "UPDATE $this->table SET $this->expirationCol = {$this->getCurrentTimestampStatement()} + $ttl, $this->tokenCol = :token1 WHERE $this->idCol = :id AND ($this->tokenCol = :token2 OR $this->expirationCol <= {$this->getCurrentTimestampStatement()})";
        $stmt = $this->getConnection()->prepare($sql);

        $uniqueToken = $this->getUniqueToken($key);
        $stmt->bindValue(':id', $this->getHashedKey($key));
        $stmt->bindValue(':token1', $uniqueToken);
        $stmt->bindValue(':token2', $uniqueToken);
        
$this->randomlyPrune();
        $this->checkNotExpired($key);
    }

    /** * @return void */
    public function putOffExpiration(Key $key$ttl)
    {
        if ($ttl < 1) {
            throw new InvalidTtlException(sprintf('"%s()" expects a TTL greater or equals to 1 second. Got "%s".', __METHOD__, $ttl));
        }

        $key->reduceLifetime($ttl);

        $sql = "UPDATE $this->table SET $this->expirationCol = {$this->getCurrentTimestampStatement()} + ?, $this->tokenCol = ? WHERE $this->idCol = ? AND ($this->tokenCol = ? OR $this->expirationCol <= {$this->getCurrentTimestampStatement()})";
        $uniqueToken = $this->getUniqueToken($key);

        $result = $this->conn->executeQuery($sql[
            $ttl,
            $uniqueToken,
            $this->getHashedKey($key),
            

            if (null === $this->options['collection']) {
                throw new InvalidArgumentException(sprintf('"%s()" requires the "collection" in the URI querystring or option.', __METHOD__));
            }
        }

        if ($this->options['gcProbability'] < 0.0 || $this->options['gcProbability'] > 1.0) {
            throw new InvalidArgumentException(sprintf('"%s()" gcProbability must be a float from 0.0 to 1.0, "%f" given.', __METHOD__, $this->options['gcProbability']));
        }

        if ($this->initialTtl <= 0) {
            throw new InvalidTtlException(sprintf('"%s()" expects a strictly positive TTL, got "%d".', __METHOD__, $this->initialTtl));
        }
    }

    /** * Extract default database and collection from given connection URI and remove collection querystring. * * Non-standard parameters are removed from the URI to improve libmongoc's re-use of connections. * * @see https://www.php.net/manual/en/mongodb.connection-handling.php */
    private function skimUri(string $uri): string
    {


        $this->checkNotExpired($key);
    }

    /** * @return void */
    public function putOffExpiration(Key $key, float $ttl)
    {
        if ($ttl < 1) {
            throw new InvalidTtlException(sprintf('"%s()" expects a TTL greater or equals to 1 second. Got %s.', __METHOD__, $ttl));
        }

        // Interface defines a float value but Store required an integer.         $ttl = (int) ceil($ttl);

        $token = $this->getUniqueToken($key);

        [$value$cas] = $this->getValueAndCas($key);

        $key->reduceLifetime($ttl);
        // Could happens when we ask a putOff after a timeout but in luck nobody steal the lock
private bool $supportTime;

    /** * @param float $initialTtl The expiration delay of locks in seconds */
    public function __construct(
        private \Redis|Relay|\RedisArray|\RedisCluster|\Predis\ClientInterface $redis,
        private float $initialTtl = 300.0,
    ) {
        if ($initialTtl <= 0) {
            throw new InvalidTtlException(sprintf('"%s()" expects a strictly positive TTL. Got %d.', __METHOD__, $initialTtl));
        }
    }

    /** * @return void */
    public function save(Key $key)
    {
        $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 '.
private string $tokenCol = 'key_token';
    private string $expirationCol = 'key_expiration';
    private float $gcProbability;
    private int $initialTtl;

    private function init(array $options, float $gcProbability, int $initialTtl): void
    {
        if ($gcProbability < 0 || $gcProbability > 1) {
            throw new InvalidArgumentException(sprintf('"%s" requires gcProbability between 0 and 1, "%f" given.', __METHOD__, $gcProbability));
        }
        if ($initialTtl < 1) {
            throw new InvalidTtlException(sprintf('"%s()" expects a strictly positive TTL, "%d" given.', __METHOD__, $initialTtl));
        }

        $this->table = $options['db_table'] ?? $this->table;
        $this->idCol = $options['db_id_col'] ?? $this->idCol;
        $this->tokenCol = $options['db_token_col'] ?? $this->tokenCol;
        $this->expirationCol = $options['db_expiration_col'] ?? $this->expirationCol;

        $this->gcProbability = $gcProbability;
        $this->initialTtl = $initialTtl;
    }

    
Home | Imprint | This part of the site doesn't use cookies.