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

Commit 92d2ea6

Browse filesBrowse files
committed
fix compatibility with redis extension 6.0.3+
1 parent 5cffe22 commit 92d2ea6
Copy full SHA for 92d2ea6

File tree

3 files changed

+102
-26
lines changed
Filter options

3 files changed

+102
-26
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Tests/Traits/RedisProxiesTest.php
+20-1Lines changed: 20 additions & 1 deletion
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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Traits/Redis6Proxy.php
+1-25Lines changed: 1 addition & 25 deletions
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());
+81Lines changed: 81 additions & 0 deletions
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)())->_compress(...\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+
}

0 commit comments

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