Skip to content

Commit a2c62a9

Browse files
feature #62326 [Cache][Messenger] re-allow ext-redis 6.1 (xabbuh)
This PR was merged into the 7.4 branch. Discussion ---------- [Cache][Messenger] re-allow ext-redis 6.1 | Q | A | ------------- | --- | Branch? | 7.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | | License | MIT Commits ------- d69f7c2 re-allow ext-redis 6.1
2 parents 97f1c2b + d69f7c2 commit a2c62a9

File tree

11 files changed

+115
-54
lines changed

11 files changed

+115
-54
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@
170170
},
171171
"conflict": {
172172
"ext-psr": "<1.1|>=2",
173-
"ext-redis": "<6.2",
173+
"ext-redis": "<6.1",
174174
"ext-relay": "<0.12.1",
175175
"amphp/amp": "<2.5",
176176
"async-aws/core": "<1.5",

src/Symfony/Component/Cache/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CHANGELOG
44
7.4
55
---
66

7-
* Bump ext-redis to 6.2 and ext-relay to 0.12 minimum
7+
* Bump ext-redis to 6.1 and ext-relay to 0.12 minimum
88

99
7.3
1010
---
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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.2.0', '>=')) {
15+
/**
16+
* @internal
17+
*/
18+
trait Redis62ProxyTrait
19+
{
20+
public function expiremember($key, $field, $ttl, $unit = null): \Redis|false|int
21+
{
22+
return $this->initializeLazyObject()->expiremember(...\func_get_args());
23+
}
24+
25+
public function expirememberat($key, $field, $timestamp): \Redis|false|int
26+
{
27+
return $this->initializeLazyObject()->expirememberat(...\func_get_args());
28+
}
29+
30+
public function getWithMeta($key): \Redis|array|false
31+
{
32+
return $this->initializeLazyObject()->getWithMeta(...\func_get_args());
33+
}
34+
35+
public function serverName(): false|string
36+
{
37+
return $this->initializeLazyObject()->serverName(...\func_get_args());
38+
}
39+
40+
public function serverVersion(): false|string
41+
{
42+
return $this->initializeLazyObject()->serverVersion(...\func_get_args());
43+
}
44+
}
45+
} else {
46+
/**
47+
* @internal
48+
*/
49+
trait Redis62ProxyTrait
50+
{
51+
}
52+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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.2.0', '>=')) {
15+
/**
16+
* @internal
17+
*/
18+
trait RedisCluster62ProxyTrait
19+
{
20+
public function expiremember($key, $field, $ttl, $unit = null): \Redis|false|int
21+
{
22+
return $this->initializeLazyObject()->expiremember(...\func_get_args());
23+
}
24+
25+
public function expirememberat($key, $field, $timestamp): \Redis|false|int
26+
{
27+
return $this->initializeLazyObject()->expirememberat(...\func_get_args());
28+
}
29+
30+
public function getdel($key): mixed
31+
{
32+
return $this->initializeLazyObject()->getdel(...\func_get_args());
33+
}
34+
35+
public function getWithMeta($key): \RedisCluster|array|false
36+
{
37+
return $this->initializeLazyObject()->getWithMeta(...\func_get_args());
38+
}
39+
}
40+
} else {
41+
/**
42+
* @internal
43+
*/
44+
trait RedisCluster62ProxyTrait
45+
{
46+
}
47+
}

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

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class);
2424
*/
2525
class RedisClusterProxy extends \RedisCluster implements ResetInterface, LazyObjectInterface
2626
{
27+
use RedisCluster62ProxyTrait;
2728
use RedisProxyTrait {
2829
resetLazyObject as reset;
2930
}
@@ -273,16 +274,6 @@ public function expireat($key, $timestamp, $mode = null): \RedisCluster|bool
273274
return $this->initializeLazyObject()->expireat(...\func_get_args());
274275
}
275276

276-
public function expiremember($key, $field, $ttl, $unit = null): \Redis|false|int
277-
{
278-
return $this->initializeLazyObject()->expiremember(...\func_get_args());
279-
}
280-
281-
public function expirememberat($key, $field, $timestamp): \Redis|false|int
282-
{
283-
return $this->initializeLazyObject()->expirememberat(...\func_get_args());
284-
}
285-
286277
public function expiretime($key): \RedisCluster|false|int
287278
{
288279
return $this->initializeLazyObject()->expiretime(...\func_get_args());
@@ -353,21 +344,11 @@ public function get($key): mixed
353344
return $this->initializeLazyObject()->get(...\func_get_args());
354345
}
355346

356-
public function getWithMeta($key): \RedisCluster|array|false
357-
{
358-
return $this->initializeLazyObject()->getWithMeta(...\func_get_args());
359-
}
360-
361347
public function getbit($key, $value): \RedisCluster|false|int
362348
{
363349
return $this->initializeLazyObject()->getbit(...\func_get_args());
364350
}
365351

366-
public function getdel($key): mixed
367-
{
368-
return $this->initializeLazyObject()->getdel(...\func_get_args());
369-
}
370-
371352
public function getex($key, $options = []): \RedisCluster|false|string
372353
{
373354
return $this->initializeLazyObject()->getex(...\func_get_args());

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

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class);
2424
*/
2525
class RedisProxy extends \Redis implements ResetInterface, LazyObjectInterface
2626
{
27+
use Redis62ProxyTrait;
2728
use RedisProxyTrait {
2829
resetLazyObject as reset;
2930
}
@@ -273,16 +274,6 @@ public function expireAt($key, $timestamp, $mode = null): \Redis|bool
273274
return $this->initializeLazyObject()->expireAt(...\func_get_args());
274275
}
275276

276-
public function expiremember($key, $field, $ttl, $unit = null): \Redis|false|int
277-
{
278-
return $this->initializeLazyObject()->expiremember(...\func_get_args());
279-
}
280-
281-
public function expirememberat($key, $field, $timestamp): \Redis|false|int
282-
{
283-
return $this->initializeLazyObject()->expirememberat(...\func_get_args());
284-
}
285-
286277
public function expiretime($key): \Redis|false|int
287278
{
288279
return $this->initializeLazyObject()->expiretime(...\func_get_args());
@@ -448,11 +439,6 @@ public function getTransferredBytes(): array
448439
return $this->initializeLazyObject()->getTransferredBytes(...\func_get_args());
449440
}
450441

451-
public function getWithMeta($key): \Redis|array|false
452-
{
453-
return $this->initializeLazyObject()->getWithMeta(...\func_get_args());
454-
}
455-
456442
public function getset($key, $value): \Redis|false|string
457443
{
458444
return $this->initializeLazyObject()->getset(...\func_get_args());
@@ -913,16 +899,6 @@ public function select($db): \Redis|bool
913899
return $this->initializeLazyObject()->select(...\func_get_args());
914900
}
915901

916-
public function serverName(): false|string
917-
{
918-
return $this->initializeLazyObject()->serverName(...\func_get_args());
919-
}
920-
921-
public function serverVersion(): false|string
922-
{
923-
return $this->initializeLazyObject()->serverVersion(...\func_get_args());
924-
}
925-
926902
public function set($key, $value, $options = null): \Redis|bool|string
927903
{
928904
return $this->initializeLazyObject()->set(...\func_get_args());

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public static function createConnection(#[\SensitiveParameter] string $dsn, arra
193193
}
194194

195195
if (isset($params['sentinel']) && !class_exists(\Predis\Client::class) && !class_exists(\RedisSentinel::class) && !class_exists(Sentinel::class)) {
196-
throw new CacheException('Redis Sentinel support requires one of: "predis/predis", "ext-redis >= 5.2", "ext-relay".');
196+
throw new CacheException('Redis Sentinel support requires one of: "predis/predis", "ext-redis >= 6.1", "ext-relay".');
197197
}
198198

199199
foreach (['lazy', 'persistent', 'cluster'] as $option) {
@@ -224,7 +224,7 @@ public static function createConnection(#[\SensitiveParameter] string $dsn, arra
224224
};
225225

226226
if (isset($params['sentinel']) && !is_a($class, \Predis\Client::class, true) && !class_exists(\RedisSentinel::class) && !class_exists(Sentinel::class)) {
227-
throw new CacheException(\sprintf('Cannot use Redis Sentinel: class "%s" does not extend "Predis\Client" and neither ext-redis >= 5.2 nor ext-relay have been found.', $class));
227+
throw new CacheException(\sprintf('Cannot use Redis Sentinel: class "%s" does not extend "Predis\Client" and neither ext-redis >= 6.1 nor ext-relay have been found.', $class));
228228
}
229229

230230
$isRedisExt = is_a($class, \Redis::class, true);

src/Symfony/Component/Cache/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"symfony/var-dumper": "^6.4|^7.0|^8.0"
4444
},
4545
"conflict": {
46-
"ext-redis": "<6.2",
46+
"ext-redis": "<6.1",
4747
"ext-relay": "<0.12.1",
4848
"doctrine/dbal": "<3.6",
4949
"symfony/dependency-injection": "<6.4",

src/Symfony/Component/Messenger/Bridge/Redis/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CHANGELOG
44
7.4
55
---
66

7-
* Bump ext-redis to 6.2 and ext-relay to 0.12 minimum
7+
* Bump ext-redis to 6.1 and ext-relay to 0.12 minimum
88

99
7.3
1010
---

src/Symfony/Component/Messenger/Bridge/Redis/Transport/Connection.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function __construct(array $options, \Redis|Relay|\RedisCluster|null $red
7979
$sentinelMaster = $options['sentinel'] ?? $options['redis_sentinel'] ?? $options['sentinel_master'] ?? null;
8080

8181
if (null !== $sentinelMaster && !class_exists(\RedisSentinel::class) && !class_exists(Sentinel::class)) {
82-
throw new InvalidArgumentException('Redis Sentinel support requires ext-redis>=5.2, or ext-relay.');
82+
throw new InvalidArgumentException('Redis Sentinel support requires ext-redis>=6.1, or ext-relay.');
8383
}
8484

8585
if (null !== $sentinelMaster && $redis instanceof \RedisCluster) {
@@ -697,6 +697,7 @@ public function getMessageCount(): int
697697
}
698698

699699
// Iterate through the stream. See https://redis.io/commands/xrange/#iterating-a-stream.
700+
$useExclusiveRangeInterval = version_compare(phpversion('redis'), '6.2.0', '>=');
700701
$total = 0;
701702
while (true) {
702703
if (!$range = $redis->xRange($this->stream, $lastDeliveredId, '+', 100)) {
@@ -705,7 +706,11 @@ public function getMessageCount(): int
705706

706707
$total += \count($range);
707708

708-
$lastDeliveredId = preg_replace_callback('#\d+$#', static fn (array $matches) => (int) $matches[0] + 1, array_key_last($range));
709+
if ($useExclusiveRangeInterval) {
710+
$lastDeliveredId = preg_replace_callback('#\d+$#', static fn (array $matches) => (int) $matches[0] + 1, array_key_last($range));
711+
} else {
712+
$lastDeliveredId = '('.array_key_last($range);
713+
}
709714
}
710715
}
711716

0 commit comments

Comments
 (0)