Skip to content

[Cache] fix compatibility with redis extension 6.0.3+ #57885

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

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/Symfony/Component/Cache/Tests/Traits/RedisProxiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,34 @@ public function testRedisProxy($class)
{
$version = version_compare(phpversion('redis'), '6', '>') ? '6' : '5';
$proxy = file_get_contents(\dirname(__DIR__, 2)."/Traits/{$class}{$version}Proxy.php");
$proxy = substr($proxy, 0, 4 + strpos($proxy, '[];'));
$expected = substr($proxy, 0, 4 + strpos($proxy, '[];'));
$methods = [];

foreach ((new \ReflectionClass(sprintf('Symfony\Component\Cache\Traits\\%s%dProxy', $class, $version)))->getMethods() as $method) {
if ('reset' === $method->name || method_exists(LazyProxyTrait::class, $method->name)) {
continue;
}
$return = $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
$methods[$method->name] = "\n ".ProxyHelper::exportSignature($method, false, $args)."\n".<<<EOPHP
{
{$return}(\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$method->name}({$args});
}

EOPHP;
}

uksort($methods, 'strnatcmp');
$proxy .= implode('', $methods)."}\n";

$methods = [];

foreach ((new \ReflectionClass($class))->getMethods() as $method) {
if ('reset' === $method->name || method_exists(LazyProxyTrait::class, $method->name)) {
continue;
}
$return = $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
$methods[] = "\n ".ProxyHelper::exportSignature($method, false, $args)."\n".<<<EOPHP
$methods[$method->name] = "\n ".ProxyHelper::exportSignature($method, false, $args)."\n".<<<EOPHP
{
{$return}(\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$method->name}({$args});
}
Expand Down
26 changes: 1 addition & 25 deletions src/Symfony/Component/Cache/Traits/Redis6Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class);
*/
class Redis6Proxy extends \Redis implements ResetInterface, LazyObjectInterface
{
use Redis6ProxyTrait;
use LazyProxyTrait {
resetLazyObject as reset;
}
Expand Down Expand Up @@ -226,11 +227,6 @@ public function discard(): \Redis|bool
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->discard(...\func_get_args());
}

public function dump($key): \Redis|string
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->dump(...\func_get_args());
}

public function echo($str): \Redis|false|string
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->echo(...\func_get_args());
Expand Down Expand Up @@ -511,16 +507,6 @@ public function hMset($key, $fieldvals): \Redis|bool
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->hMset(...\func_get_args());
}

public function hRandField($key, $options = null): \Redis|array|string
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->hRandField(...\func_get_args());
}

public function hSet($key, $member, $value): \Redis|false|int
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->hSet(...\func_get_args());
}

public function hSetNx($key, $field, $value): \Redis|bool
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->hSetNx(...\func_get_args());
Expand Down Expand Up @@ -651,11 +637,6 @@ public function ltrim($key, $start, $end): \Redis|bool
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->ltrim(...\func_get_args());
}

public function mget($keys): \Redis|array
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->mget(...\func_get_args());
}

public function migrate($host, $port, $key, $dstdb, $timeout, $copy = false, $replace = false, #[\SensitiveParameter] $credentials = null): \Redis|bool
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->migrate(...\func_get_args());
Expand Down Expand Up @@ -866,11 +847,6 @@ public function sPop($key, $count = 0): \Redis|array|false|string
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->sPop(...\func_get_args());
}

public function sRandMember($key, $count = 0): \Redis|array|false|string
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->sRandMember(...\func_get_args());
}

public function sUnion($key, ...$other_keys): \Redis|array|false
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->sUnion(...\func_get_args());
Expand Down
81 changes: 81 additions & 0 deletions src/Symfony/Component/Cache/Traits/Redis6ProxyTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Cache\Traits;

if (version_compare(phpversion('redis'), '6.1.0', '>=')) {
/**
* @internal
*/
trait Redis6ProxyTrait
{
public function dump($key): \Redis|string|false
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->dump(...\func_get_args());
}

public function hRandField($key, $options = null): \Redis|array|string|false
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->hRandField(...\func_get_args());
}

public function hSet($key, $fields_and_vals): \Redis|false|int

Check failure on line 30 in src/Symfony/Component/Cache/Traits/Redis6ProxyTrait.php

View workflow job for this annotation

GitHub Actions / Psalm

ParamNameMismatch

src/Symfony/Component/Cache/Traits/Redis6ProxyTrait.php:30:36: ParamNameMismatch: Argument 2 of Symfony\Component\Cache\Traits\Redis6ProxyTrait::hSet has wrong name $fields_and_vals, expecting $member as defined by Redis::hSet (see https://psalm.dev/230)

Check failure on line 30 in src/Symfony/Component/Cache/Traits/Redis6ProxyTrait.php

View workflow job for this annotation

GitHub Actions / Psalm

ParamNameMismatch

src/Symfony/Component/Cache/Traits/Redis6ProxyTrait.php:30:36: ParamNameMismatch: Argument 2 of Symfony\Component\Cache\Traits\Redis6ProxyTrait::hSet has wrong name $fields_and_vals, expecting $member as defined by Redis::hSet (see https://psalm.dev/230)
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->hSet(...\func_get_args());
}

public function mget($keys): \Redis|array|false
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->mget(...\func_get_args());
}

public function sRandMember($key, $count = 0): mixed
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->sRandMember(...\func_get_args());
}

public function waitaof($numlocal, $numreplicas, $timeout): \Redis|array|false
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->waitaof(...\func_get_args());
}
}
} else {
/**
* @internal
*/
trait Redis6ProxyTrait

Check failure on line 54 in src/Symfony/Component/Cache/Traits/Redis6ProxyTrait.php

View workflow job for this annotation

GitHub Actions / Psalm

DuplicateClass

src/Symfony/Component/Cache/Traits/Redis6ProxyTrait.php:54:11: DuplicateClass: Class Symfony\Component\Cache\Traits\Redis6ProxyTrait has already been defined in /home/runner/work/symfony/symfony/src/Symfony/Component/Cache/Traits/Redis6ProxyTrait.php (see https://psalm.dev/071)

Check failure on line 54 in src/Symfony/Component/Cache/Traits/Redis6ProxyTrait.php

View workflow job for this annotation

GitHub Actions / Psalm

DuplicateClass

src/Symfony/Component/Cache/Traits/Redis6ProxyTrait.php:54:11: DuplicateClass: Class Symfony\Component\Cache\Traits\Redis6ProxyTrait has already been defined in /home/runner/work/symfony/symfony/src/Symfony/Component/Cache/Traits/Redis6ProxyTrait.php (see https://psalm.dev/071)
{
public function dump($key): \Redis|string

Check failure on line 56 in src/Symfony/Component/Cache/Traits/Redis6ProxyTrait.php

View workflow job for this annotation

GitHub Actions / Psalm

MethodSignatureMismatch

src/Symfony/Component/Cache/Traits/Redis6ProxyTrait.php:56:9: MethodSignatureMismatch: Method Symfony\Component\Cache\Traits\Redis6ProxyTrait::dump with return type 'Redis|false|string' is different to return type 'string' of inherited method Redis::dump (see https://psalm.dev/042)

Check failure on line 56 in src/Symfony/Component/Cache/Traits/Redis6ProxyTrait.php

View workflow job for this annotation

GitHub Actions / Psalm

MethodSignatureMismatch

src/Symfony/Component/Cache/Traits/Redis6ProxyTrait.php:56:9: MethodSignatureMismatch: Method Symfony\Component\Cache\Traits\Redis6ProxyTrait::dump with return type 'Redis|false|string' is different to return type 'string' of inherited method Redis::dump (see https://psalm.dev/042)
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->dump(...\func_get_args());
}

public function hRandField($key, $options = null): \Redis|array|string
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->hRandField(...\func_get_args());
}

public function hSet($key, $member, $value): \Redis|false|int

Check failure on line 66 in src/Symfony/Component/Cache/Traits/Redis6ProxyTrait.php

View workflow job for this annotation

GitHub Actions / Psalm

MethodSignatureMismatch

src/Symfony/Component/Cache/Traits/Redis6ProxyTrait.php:66:9: MethodSignatureMismatch: Method Symfony\Component\Cache\Traits\Redis6ProxyTrait::hSet has fewer parameters than parent method Redis::hSet (see https://psalm.dev/042)

Check failure on line 66 in src/Symfony/Component/Cache/Traits/Redis6ProxyTrait.php

View workflow job for this annotation

GitHub Actions / Psalm

MethodSignatureMismatch

src/Symfony/Component/Cache/Traits/Redis6ProxyTrait.php:66:9: MethodSignatureMismatch: Method Symfony\Component\Cache\Traits\Redis6ProxyTrait::hSet has fewer parameters than parent method Redis::hSet (see https://psalm.dev/042)
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->hSet(...\func_get_args());
}

public function mget($keys): \Redis|array
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->mget(...\func_get_args());
}

public function sRandMember($key, $count = 0): \Redis|array|false|string

Check failure on line 76 in src/Symfony/Component/Cache/Traits/Redis6ProxyTrait.php

View workflow job for this annotation

GitHub Actions / Psalm

MethodSignatureMismatch

src/Symfony/Component/Cache/Traits/Redis6ProxyTrait.php:76:9: MethodSignatureMismatch: Method Symfony\Component\Cache\Traits\Redis6ProxyTrait::sRandMember with return type 'mixed' is different to return type 'Redis|array<array-key, mixed>|false|string' of inherited method Redis::sRandMember (see https://psalm.dev/042)
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->sRandMember(...\func_get_args());
}
}
}
6 changes: 1 addition & 5 deletions src/Symfony/Component/Cache/Traits/RedisCluster6Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class);
*/
class RedisCluster6Proxy extends \RedisCluster implements ResetInterface, LazyObjectInterface
{
use RedisCluster6ProxyTrait;
use LazyProxyTrait {
resetLazyObject as reset;
}
Expand Down Expand Up @@ -656,11 +657,6 @@ public function pttl($key): \RedisCluster|false|int
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->pttl(...\func_get_args());
}

public function publish($channel, $message): \RedisCluster|bool
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->publish(...\func_get_args());
}

public function pubsub($key_or_address, ...$values): mixed
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->pubsub(...\func_get_args());
Expand Down
46 changes: 46 additions & 0 deletions src/Symfony/Component/Cache/Traits/RedisCluster6ProxyTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Cache\Traits;

if (version_compare(phpversion('redis'), '6.1.0', '>')) {
/**
* @internal
*/
trait RedisCluster6ProxyTrait
{
public function getex($key, $options = []): \RedisCluster|string|false
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->getex(...\func_get_args());
}

public function publish($channel, $message): \RedisCluster|bool|int
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->publish(...\func_get_args());
}

public function waitaof($key_or_address, $numlocal, $numreplicas, $timeout): \RedisCluster|array|false
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->waitaof(...\func_get_args());
}
}
} else {
/**
* @internal
*/
trait RedisCluster6ProxyTrait

Check failure on line 39 in src/Symfony/Component/Cache/Traits/RedisCluster6ProxyTrait.php

View workflow job for this annotation

GitHub Actions / Psalm

DuplicateClass

src/Symfony/Component/Cache/Traits/RedisCluster6ProxyTrait.php:39:11: DuplicateClass: Class Symfony\Component\Cache\Traits\RedisCluster6ProxyTrait has already been defined in /home/runner/work/symfony/symfony/src/Symfony/Component/Cache/Traits/RedisCluster6ProxyTrait.php (see https://psalm.dev/071)
{
public function publish($channel, $message): \RedisCluster|bool
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->publish(...\func_get_args());
}
}
}