Neos\Cache\Backend\RedisBackend::set PHP Метод

set() публичный Метод

Saves data in the cache.
public set ( string $entryIdentifier, string $data, array $tags = [], integer $lifetime = null ) : void
$entryIdentifier string An identifier for this specific cache entry
$data string The data to be stored
$tags array Tags to associate with this cache entry. If the backend does not support tags, this option can be ignored.
$lifetime integer Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited lifetime.
Результат void
    public function set($entryIdentifier, $data, array $tags = [], $lifetime = null)
    {
        if ($this->isFrozen()) {
            throw new \RuntimeException(sprintf('Cannot add or modify cache entry because the backend of cache "%s" is frozen.', $this->cacheIdentifier), 1323344192);
        }
        if ($lifetime === null) {
            $lifetime = $this->defaultLifetime;
        }
        $setOptions = [];
        if ($lifetime > 0) {
            $setOptions['ex'] = $lifetime;
        }
        $this->redis->multi();
        $result = $this->redis->set($this->buildKey('entry:' . $entryIdentifier), $this->compress($data), $setOptions);
        if (!$result instanceof \Redis) {
            $this->verifyRedisVersionIsSupported();
        }
        $this->redis->lRem($this->buildKey('entries'), $entryIdentifier, 0);
        $this->redis->rPush($this->buildKey('entries'), $entryIdentifier);
        foreach ($tags as $tag) {
            $this->redis->sAdd($this->buildKey('tag:' . $tag), $entryIdentifier);
            $this->redis->sAdd($this->buildKey('tags:' . $entryIdentifier), $tag);
        }
        $this->redis->exec();
    }

Usage Example

 /**
  * @test
  */
 public function expiredEntriesAreSkippedWhenIterating()
 {
     $this->backend->set('entry1', 'foo', [], 1);
     sleep(2);
     $this->assertFalse($this->backend->has('entry1'));
     $actualEntries = [];
     foreach ($this->backend as $key => $value) {
         $actualEntries[] = $key;
     }
     $this->assertEmpty($actualEntries, 'Entries should be empty');
 }
All Usage Examples Of Neos\Cache\Backend\RedisBackend::set