RedisAdapter example


    protected $skippedTests = [
        'testExpiration' => 'Testing expiration slows down the test suite',
        'testHasItemReturnsFalseWhenDeferredItemIsExpired' => 'Testing expiration slows down the test suite',
        'testDefaultLifeTime' => 'Testing expiration slows down the test suite',
    ];

    protected static \Redis|Relay|\RedisArray|\RedisCluster|\Predis\ClientInterface $redis;

    public function createCachePool(int $defaultLifetime = 0, string $testMethod = null): CacheItemPoolInterface
    {
        return new RedisAdapter(self::$redisstr_replace('\\', '.', __CLASS__)$defaultLifetime);
    }

    public static function setUpBeforeClass(): void
    {
        if (!\extension_loaded('redis')) {
            throw new SkippedTestSuiteError('Extension redis required.');
        }
        try {
            (new \Redis())->connect(...explode(':', getenv('REDIS_HOST')));
        } catch (\Exception $e) {
            throw new SkippedTestSuiteError(getenv('REDIS_HOST').': '.$e->getMessage());
        }
self::$redis = AbstractAdapter::createConnection('redis:?host['.str_replace(' ', ']&host[', $hosts).']', ['lazy' => true, 'redis_cluster' => true]);
        self::$redis->setOption(\Redis::OPT_PREFIX, 'prefix_');
    }

    public function createCachePool(int $defaultLifetime = 0, string $testMethod = null): CacheItemPoolInterface
    {
        if ('testClearWithPrefix' === $testMethod && \defined('Redis::SCAN_PREFIX')) {
            self::$redis->setOption(\Redis::OPT_SCAN, \Redis::SCAN_PREFIX);
        }

        $this->assertInstanceOf(RedisClusterProxy::class, self::$redis);
        $adapter = new RedisAdapter(self::$redisstr_replace('\\', '.', __CLASS__)$defaultLifetime);

        return $adapter;
    }

    /** * @dataProvider provideFailedCreateConnection */
    public function testFailedCreateConnection(string $dsn)
    {
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('Redis connection ');
        
'testPrune' => 'RedisAdapter does not implement PruneableInterface.',
    ];

    public static function setUpBeforeClass(): void
    {
        parent::setUpBeforeClass();
        self::$redis = AbstractAdapter::createConnection('redis://'.getenv('REDIS_HOST'));
    }

    public function createCachePool($defaultLifetime = 0, string $testMethod = null): CacheItemPoolInterface
    {
        return new ProxyAdapter(new RedisAdapter(self::$redisstr_replace('\\', '.', __CLASS__), 100), 'ProxyNS', $defaultLifetime);
    }

    public function testSaveItemPermanently()
    {
        $setCacheItemExpiry = \Closure::bind(
            static function DCacheItem $item$expiry) {
                $item->expiry = $expiry;

                return $item;
            },
            null,
            
Home | Imprint | This part of the site doesn't use cookies.