Skip to content

Commit 701bebd

Browse files
committed
fix compatibility with redis extension 6.0.3+
1 parent 5cffe22 commit 701bebd

File tree

5 files changed

+149
-31
lines changed

5 files changed

+149
-31
lines changed

src/Symfony/Component/Cache/Tests/Traits/RedisProxiesTest.php

+20-1
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,34 @@ public function testRedisProxy($class)
2929
{
3030
$version = version_compare(phpversion('redis'), '6', '>') ? '6' : '5';
3131
$proxy = file_get_contents(\dirname(__DIR__, 2)."/Traits/{$class}{$version}Proxy.php");
32+
$proxy = substr($proxy, 0, 4 + strpos($proxy, '[];'));
3233
$expected = substr($proxy, 0, 4 + strpos($proxy, '[];'));
3334
$methods = [];
3435

36+
foreach ((new \ReflectionClass(sprintf('Symfony\Component\Cache\Traits\\%s%dProxy', $class, $version)))->getMethods() as $method) {
37+
if ('reset' === $method->name || method_exists(LazyProxyTrait::class, $method->name)) {
38+
continue;
39+
}
40+
$return = $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
41+
$methods[$method->name] = "\n ".ProxyHelper::exportSignature($method, false, $args)."\n".<<<EOPHP
42+
{
43+
{$return}(\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$method->name}({$args});
44+
}
45+
46+
EOPHP;
47+
}
48+
49+
uksort($methods, 'strnatcmp');
50+
$proxy .= implode('', $methods)."}\n";
51+
52+
$methods = [];
53+
3554
foreach ((new \ReflectionClass($class))->getMethods() as $method) {
3655
if ('reset' === $method->name || method_exists(LazyProxyTrait::class, $method->name)) {
3756
continue;
3857
}
3958
$return = $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
40-
$methods[] = "\n ".ProxyHelper::exportSignature($method, false, $args)."\n".<<<EOPHP
59+
$methods[$method->name] = "\n ".ProxyHelper::exportSignature($method, false, $args)."\n".<<<EOPHP
4160
{
4261
{$return}(\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$method->name}({$args});
4362
}

src/Symfony/Component/Cache/Traits/Redis6Proxy.php

+1-25
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class);
2525
*/
2626
class Redis6Proxy extends \Redis implements ResetInterface, LazyObjectInterface
2727
{
28+
use Redis6ProxyTrait;
2829
use LazyProxyTrait {
2930
resetLazyObject as reset;
3031
}
@@ -226,11 +227,6 @@ public function discard(): \Redis|bool
226227
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->discard(...\func_get_args());
227228
}
228229

229-
public function dump($key): \Redis|string
230-
{
231-
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->dump(...\func_get_args());
232-
}
233-
234230
public function echo($str): \Redis|false|string
235231
{
236232
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->echo(...\func_get_args());
@@ -511,16 +507,6 @@ public function hMset($key, $fieldvals): \Redis|bool
511507
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->hMset(...\func_get_args());
512508
}
513509

514-
public function hRandField($key, $options = null): \Redis|array|string
515-
{
516-
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->hRandField(...\func_get_args());
517-
}
518-
519-
public function hSet($key, $member, $value): \Redis|false|int
520-
{
521-
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->hSet(...\func_get_args());
522-
}
523-
524510
public function hSetNx($key, $field, $value): \Redis|bool
525511
{
526512
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->hSetNx(...\func_get_args());
@@ -651,11 +637,6 @@ public function ltrim($key, $start, $end): \Redis|bool
651637
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->ltrim(...\func_get_args());
652638
}
653639

654-
public function mget($keys): \Redis|array
655-
{
656-
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->mget(...\func_get_args());
657-
}
658-
659640
public function migrate($host, $port, $key, $dstdb, $timeout, $copy = false, $replace = false, #[\SensitiveParameter] $credentials = null): \Redis|bool
660641
{
661642
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->migrate(...\func_get_args());
@@ -866,11 +847,6 @@ public function sPop($key, $count = 0): \Redis|array|false|string
866847
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->sPop(...\func_get_args());
867848
}
868849

869-
public function sRandMember($key, $count = 0): \Redis|array|false|string
870-
{
871-
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->sRandMember(...\func_get_args());
872-
}
873-
874850
public function sUnion($key, ...$other_keys): \Redis|array|false
875851
{
876852
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->sUnion(...\func_get_args());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Cache\Traits;
13+
14+
if (version_compare(phpversion('redis'), '6.0.2', '>')) {
15+
/**
16+
* @internal
17+
*/
18+
trait Redis6ProxyTrait
19+
{
20+
public function dump($key): \Redis|string|false
21+
{
22+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->dump(...\func_get_args());
23+
}
24+
25+
public function hRandField($key, $options = null): \Redis|array|string|false
26+
{
27+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->hRandField(...\func_get_args());
28+
}
29+
30+
public function hSet($key, $fields_and_vals): \Redis|false|int
31+
{
32+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->hSet(...\func_get_args());
33+
}
34+
35+
public function mget($keys): \Redis|array|false
36+
{
37+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->mget(...\func_get_args());
38+
}
39+
40+
public function sRandMember($key, $count = 0): mixed
41+
{
42+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->sRandMember(...\func_get_args());
43+
}
44+
45+
public function waitaof($numlocal, $numreplicas, $timeout): \Redis|array|false
46+
{
47+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->waitaof(...\func_get_args());
48+
}
49+
}
50+
} else {
51+
/**
52+
* @internal
53+
*/
54+
trait Redis6ProxyTrait
55+
{
56+
public function dump($key): \Redis|string
57+
{
58+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->dump(...\func_get_args());
59+
}
60+
61+
public function hRandField($key, $options = null): \Redis|array|string
62+
{
63+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->hRandField(...\func_get_args());
64+
}
65+
66+
public function hSet($key, $member, $value): \Redis|false|int
67+
{
68+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->hSet(...\func_get_args());
69+
}
70+
71+
public function mget($keys): \Redis|array
72+
{
73+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->mget(...\func_get_args());
74+
}
75+
76+
public function sRandMember($key, $count = 0): \Redis|array|false|string
77+
{
78+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->sRandMember(...\func_get_args());
79+
}
80+
}
81+
}

src/Symfony/Component/Cache/Traits/RedisCluster6Proxy.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class);
2525
*/
2626
class RedisCluster6Proxy extends \RedisCluster implements ResetInterface, LazyObjectInterface
2727
{
28+
use RedisCluster6ProxyTrait;
2829
use LazyProxyTrait {
2930
resetLazyObject as reset;
3031
}
@@ -656,11 +657,6 @@ public function pttl($key): \RedisCluster|false|int
656657
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->pttl(...\func_get_args());
657658
}
658659

659-
public function publish($channel, $message): \RedisCluster|bool
660-
{
661-
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->publish(...\func_get_args());
662-
}
663-
664660
public function pubsub($key_or_address, ...$values): mixed
665661
{
666662
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->pubsub(...\func_get_args());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Cache\Traits;
13+
14+
if (version_compare(phpversion('redis'), '6.0.2', '>')) {
15+
/**
16+
* @internal
17+
*/
18+
trait RedisCluster6ProxyTrait
19+
{
20+
public function getex($key, $options = []): \RedisCluster|string|false
21+
{
22+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->getex(...\func_get_args());
23+
}
24+
25+
public function publish($channel, $message): \RedisCluster|bool|int
26+
{
27+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->publish(...\func_get_args());
28+
}
29+
30+
public function waitaof($key_or_address, $numlocal, $numreplicas, $timeout): \RedisCluster|array|false
31+
{
32+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->waitaof(...\func_get_args());
33+
}
34+
}
35+
} else {
36+
/**
37+
* @internal
38+
*/
39+
trait RedisCluster6ProxyTrait
40+
{
41+
public function publish($channel, $message): \RedisCluster|bool
42+
{
43+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->publish(...\func_get_args());
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)