Closed
Description
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:
When using lazy: true
parameter (in symfony container service or redis connection), the RedisProxy propagates all the function arguments to the redis::scan
function:
The problem is: redis doesn't return keys if we send $type=null as parameter
Seems to be related with: phpredis/phpredis#2362