8000 Redis v6 clear() bug when using lazy:true · Issue #51679 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Redis v6 clear() bug when using lazy:true #51679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JoniJnm opened this issue Sep 18, 2023 · 5 comments
Closed

Redis v6 clear() bug when using lazy:true #51679

JoniJnm opened this issue Sep 18, 2023 · 5 comments

Comments

@JoniJnm
Copy link
JoniJnm commented Sep 18, 2023

Symfony version(s) affected

6.3.0

Description

Redis doesn't clear the namespace when using lazy=true (on redis connection or symfony container service)

How to reproduce

$redisConnection = \Symfony\Component\Cache\Adapter\RedisAdapter::createConnection(
    'redis:?host[my-host]',
    [
        'lazy' => true
    ]
);

$redisAdapter = new \Symfony\Component\Cache\Adapter\RedisAdapter($redisConnection, 'testing');
$redis = new \Symfony\Component\Cache\Psr16Cache($redisAdapter);

$redis->set('my-key', 'my-value');
$redis->clear();
$value = $redis->get('my-key');
// here, $value is "my-value". With lazy=false $value is null

Possible Solution

I don't know if this is a bug in redis but symfony can fix it chaning the RedisProxy::scan function:

public function scan(&$iterator, $pattern = null, $count = 0, $type = null): array|false
{
    $this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)();

    if (\func_num_args() > 3) {
        return $this->lazyObjectState->realInstance->scan($iterator, $pattern, $count, $type, ...\array_slice(\func_get_args(), 4));
    } else {
        return $this->lazyObjectState->realInstance->scan($iterator, $pattern, $count);
    }
}

Note: this works only for lazy=true on redis conection but the error still exists for lazy=true on symfony container service

Additional Context

$version = phpversion("redis"); // 6.0.0

The RedisTrait::doClear function scan all the keys in the namespace:

$keys = $host instanceof \Predis\ClientInterface ? $host->scan($cursor, 'MATCH', $pattern, 'COUNT', 1000) : $host->scan($cursor, $pattern, 1000);

When using lazy: true parameter (in symfony container service or redis connection), the RedisProxy propagates all the function arguments to the redis::scan function:

return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->scan($iterator, $pattern, $count, $type, ...\array_slice(\func_get_args(), 4));

The problem is: redis doesn't return keys if we send $type=null as parameter

Seems to be related with: phpredis/phpredis#2362

@JoniJnm JoniJnm added the Bug label Sep 18, 2023
@JoniJnm JoniJnm changed the title Redis clear bug when using lazy: true Redis v6 clear() bug when using lazy:true Sep 18, 2023
@xabbuh xabbuh added the Cache label Sep 19, 2023
@nicolas-grekas
Copy link
Member

Can you please submit a bug report to phpredis? Looks like this should be fixed there.

@JoniJnm
Copy link
Author
JoniJnm commented Sep 19, 2023

I think this PR fixes the problem: phpredis/phpredis#2363 (comment)

They merged it to develop branch but I don't know when they will release a new version. You can close this issue if you want.

@JoniJnm
Copy link
Author
JoniJnm commented Sep 19, 2023

Ouh, you are the author of the fix xD

Do you know when pecl will release a new version with your changes?

@yakobe
Copy link
Contributor
yakobe commented Oct 3, 2023

Hello awesome symfony people. I also seem to be having a problem with the cache and phpredis v6. I am using the RedisTagAwareAdapter and the $cache->clear() method does not clear the cache.

However I can still invalidate specific tags with $cache->invalidateTags(['tag-name']). I have tried the newly released redis-6.0.1 but it still happens. Rolling back to redis-5.3.7 fixes the problem. Unfortunately I don't know where to even start looking 😬. Is there anything i can do to help or clarify the problem?

@OskarStark
Copy link
Contributor

As this bug is fixed upstream, lets close here.

@yakobe please open a new issue, so that we don't lost track on this, thanks

nicolas-grekas added a commit that referenced this issue Oct 13, 2023
…y behaviors of internal classes (nicolas-grekas)

This PR was merged into the 6.3 branch.

Discussion
----------

[Cache][VarExporter] Fix proxy generation to deal with edgy behaviors of internal classes

| Q             | A
| ------------- | ---
| Branch?       | 6.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #51770, #51679, #51700
| License       | MIT

Instead of #51838

This fixes the issue by not passing default values explicitly when they were not provided during the call to the method.

Commits
-------

c66a2f7 [Cache][VarExporter] Fix proxy generation to deal with edgy behaviors of internal classes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants
0