RedisConnectionFactory example

$this->getContainer()->get(Connection::class)->executeStatement('DELETE FROM cart');

        $redisCart = new Cart(Uuid::randomHex());
        $redisCart->add(
            (new LineItem('A', 'test'))
                ->setPrice(new CalculatedPrice(0, 0, new CalculatedTaxCollection()new TaxRuleCollection()))
        );

        $context = $this->getSalesChannelContext($redisCart->getToken());

        $factory = new RedisConnectionFactory('test-prefix-');
        $redis = $factory->create((string) $url);
        static::assertInstanceOf(\Redis::class$redis);
        $redis->flushAll();

        $persister = new RedisCartPersister($redis$this->getContainer()->get('event_dispatcher')$this->getContainer()->get(CartSerializationCleaner::class), false, 90);
        $persister->save($redisCart$context);

        $command = new CartMigrateCommand($redis$this->getContainer()->get(Connection::class), false, 90, $factory);
        $command->run(new ArrayInput(['from' => 'redis'])new NullOutput());

        $persister = new CartPersister(
            

    public function testPrefix(?string $aPrefix, ?string $bPrefix, bool $equals): void
    {
        /** @var string $url */
        $url = EnvironmentHelper::getVariable('REDIS_URL');

        if (!$url) {
            static::markTestSkipped('No redis server configured');
        }

        $a = (new RedisConnectionFactory($aPrefix))->create($url);
        $b = (new RedisConnectionFactory($bPrefix))->create($url);

        $a->set('foo', 'bar');
        $b->set('foo', 'foo');

        static::assertEquals($equals$a->get('foo') === $b->get('foo'));
    }

    public static function prefixProvider(): \Generator
    {
        yield 'Test different namespace' => ['namespace-1', 'namespace-2', false];
        
protected function setUp(): void
    {
        parent::setUp();

        $redisUrl = (string) EnvironmentHelper::getVariable('REDIS_URL');

        if ($redisUrl === '') {
            static::markTestSkipped('Redis is not available');
        }

        $factory = new RedisConnectionFactory();

        $redisClient = $factory->create($redisUrl);
        static::assertInstanceOf(\Redis::class$redisClient);

        $this->redis = $redisClient;
        $this->incrementer = new RedisIncrementer($this->redis);
        $this->incrementer->setPool('test');
    }

    protected function tearDown(): void
    {
        
Home | Imprint | This part of the site doesn't use cookies.