Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Cache] BC between SF 6.2 and 6.1 when using scan command with PHPRedis object lazy loaded #49959

Copy link
Copy link
Closed
@Catrixb

Description

@Catrixb
Issue body actions

Symfony version(s) affected

6.2.7

Description

When injecting a Redis (PHPRedis) instance, with lazy: true, the behaviour of the scan command is broken.
The iterator reference is not set properly and will not allow a loop to retrieve all the results from the command.
It looks like the changes introduced here causes this issue.

How to reproduce

PHP Unit test to reproduce

class ScanTest extends KernelTestCase
{
    private \Redis $redis;

    protected function setUp(): void
    {
        parent::setUp();
        /* @var \Redis $redis */
        $this->redis = $this->getService('redis_provider');
        $this->redis->flushDB();
    }

    public function testScanRetrieveAllResults(): void
    {
        $nbFixtures = 12; // default SCAN count is 10
        for ($i = 0; $i < $nbFixtures; ++$i) {
            $this->redis->set((string) $i, (string) $i);
        }

        $allKeys = [];
        $iterator = null;
        do {
            // SF 6.2 will loop infinitely
            $allKeys = array_merge($allKeys, $this->redis->scan($iterator, '*', 2));
        } while (0 !== $iterator);

        // SF 6.1 succeed, retrieves 12 elements
        $this->assertEquals($nbFixtures, count($allKeys));
    }
}

Service declaration

services:
    redis_provider:
        class: \Redis
        lazy: true # issue here
        factory: ['App\Cache\Redis\Factory\RedisConnectionFactory', 'createConnection']
        arguments:
            - '%env(REDIS_DSN)%' # redis://local_redis/0 given you have a Redis locally

Factory

namespace App\Cache\Redis\Factory;
use Symfony\Component\Cache\Adapter\RedisAdapter;

class RedisConnectionFactory
{
    public static function createConnection(string $dsn, array $options = []): \Redis
    {
            return RedisAdapter::createConnection($dsn, $options);
    }
}

Possible Solution

Not using lazy-loading. lazy: false But this does not fix the original issue.

Additional Context

Symfony version 6.2.7
PHP version 8.1
Redis version: 6.2.2
PHPRedis

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.