From 403294c48756ad54fe78cfe6d65836a2358f6ee5 Mon Sep 17 00:00:00 2001 From: Vadim Dvorovenko Date: Sat, 8 Nov 2025 21:19:23 +0700 Subject: [PATCH 1/6] [12.x] unskip tests --- tests/Integration/Cache/MemoizedStoreTest.php | 8 -------- tests/Integration/Cache/RedisStoreTest.php | 8 -------- 2 files changed, 16 deletions(-) diff --git a/tests/Integration/Cache/MemoizedStoreTest.php b/tests/Integration/Cache/MemoizedStoreTest.php index e9ec1b435d51..009906f1555f 100644 --- a/tests/Integration/Cache/MemoizedStoreTest.php +++ b/tests/Integration/Cache/MemoizedStoreTest.php @@ -13,8 +13,6 @@ use Illuminate\Cache\Events\WritingKey; use Illuminate\Contracts\Cache\Store; use Illuminate\Foundation\Testing\Concerns\InteractsWithRedis; -use Illuminate\Redis\Connections\PhpRedisClusterConnection; -use Illuminate\Redis\Connections\PredisClusterConnection; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; @@ -33,12 +31,6 @@ protected function setUp(): void $this->setUpRedis(); - $connection = $this->app['redis']->connection(); - $this->markTestSkippedWhen( - $connection instanceof PhpRedisClusterConnection || $connection instanceof PredisClusterConnection, - 'flushAll and many currently not supported for Redis Cluster connections', - ); - Config::set('cache.default', 'redis'); Redis::flushAll(); } diff --git a/tests/Integration/Cache/RedisStoreTest.php b/tests/Integration/Cache/RedisStoreTest.php index ede6e7c394f1..e4332b5b6b40 100644 --- a/tests/Integration/Cache/RedisStoreTest.php +++ b/tests/Integration/Cache/RedisStoreTest.php @@ -6,9 +6,7 @@ use Illuminate\Cache\RedisStore; use Illuminate\Foundation\Testing\Concerns\InteractsWithRedis; use Illuminate\Redis\Connections\PhpRedisClusterConnection; -use Illuminate\Redis\Connections\PredisClusterConnection; use Illuminate\Support\Facades\Cache; -use Illuminate\Support\Facades\Redis; use Illuminate\Support\Sleep; use Mockery as m; use Orchestra\Testbench\TestCase; @@ -23,12 +21,6 @@ protected function setUp(): void { $this->afterApplicationCreated(function () { $this->setUpRedis(); - - $connection = $this->app['redis']->connection(); - $this->markTestSkippedWhen( - $connection instanceof PhpRedisClusterConnection || $connection instanceof PredisClusterConnection, - 'RedisStore currently does not support tags, many and some other on Redis Cluster cluster connections', - ); }); $this->beforeApplicationDestroyed(function () { From fd67b5c113598f516535f494b3fd2a8572a2ed3f Mon Sep 17 00:00:00 2001 From: Vadim Dvorovenko Date: Sat, 8 Nov 2025 21:16:56 +0700 Subject: [PATCH 2/6] [12.x] many for RedisStore --- src/Illuminate/Cache/RedisStore.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Illuminate/Cache/RedisStore.php b/src/Illuminate/Cache/RedisStore.php index 4f18dcf5d1b9..d4296fc78509 100755 --- a/src/Illuminate/Cache/RedisStore.php +++ b/src/Illuminate/Cache/RedisStore.php @@ -14,6 +14,7 @@ class RedisStore extends TaggableStore implements LockProvider { use RetrievesMultipleKeys { + many as private manyAlias; putMany as private putManyAlias; } @@ -92,6 +93,12 @@ public function many(array $keys) $connection = $this->connection(); + // Cluster connections do not support reading multiple values if the keys hash differently... + if ($connection instanceof PhpRedisClusterConnection || + $connection instanceof PredisClusterConnection) { + return $this->manyAlias($keys); + } + $values = $connection->mget(array_map(function ($key) { return $this->prefix.$key; }, $keys)); From ab170e7f70db00f1a65e450e470ec73dccda744e Mon Sep 17 00:00:00 2001 From: Vadim Dvorovenko Date: Sun, 9 Nov 2025 02:07:39 +0700 Subject: [PATCH 3/6] [12.x] replace flushAll with flushDb in MemoizedStoreTest --- tests/Integration/Cache/MemoizedStoreTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Integration/Cache/MemoizedStoreTest.php b/tests/Integration/Cache/MemoizedStoreTest.php index 009906f1555f..74022ea8527d 100644 --- a/tests/Integration/Cache/MemoizedStoreTest.php +++ b/tests/Integration/Cache/MemoizedStoreTest.php @@ -32,7 +32,8 @@ protected function setUp(): void $this->setUpRedis(); Config::set('cache.default', 'redis'); - Redis::flushAll(); + Redis::connection(Config::get('cache.stores.redis.connection'))->flushDb(); + Redis::connection(Config::get('cache.stores.redis.lock_connection'))->flushDb(); } protected function tearDown(): void From 2a67dc1ae3a1222032e849b150717e425ccc9992 Mon Sep 17 00:00:00 2001 From: Vadim Dvorovenko Date: Sat, 8 Nov 2025 21:10:22 +0700 Subject: [PATCH 4/6] [12.x] flushStaleEntries for PhpRedisCluster in RedisTagSet --- src/Illuminate/Cache/RedisTagSet.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Cache/RedisTagSet.php b/src/Illuminate/Cache/RedisTagSet.php index 82369ff4ed00..8ea4c4ae9799 100644 --- a/src/Illuminate/Cache/RedisTagSet.php +++ b/src/Illuminate/Cache/RedisTagSet.php @@ -79,11 +79,18 @@ public function entries() */ public function flushStaleEntries() { - $this->store->connection()->pipeline(function ($pipe) { + $flushStaleEntries = function ($pipe) { foreach ($this->tagIds() as $tagKey) { $pipe->zremrangebyscore($this->store->getPrefix().$tagKey, 0, Carbon::now()->getTimestamp()); } - }); + }; + + $connection = $this->store->connection(); + if ($connection instanceof PhpRedisConnection) { + $flushStaleEntries($connection); + } else { + $connection->pipeline($flushStaleEntries); + } } /** From 0a8c7368eb8293c7b1e6c9708cc87d74e8b3d145 Mon Sep 17 00:00:00 2001 From: Vadim Dvorovenko Date: Sat, 8 Nov 2025 21:12:49 +0700 Subject: [PATCH 5/6] [12.x] flushValues for PredisCluster in RedisTaggedCache --- src/Illuminate/Cache/RedisTaggedCache.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Cache/RedisTaggedCache.php b/src/Illuminate/Cache/RedisTaggedCache.php index 7f4e30992a4a..61aaf735e890 100644 --- a/src/Illuminate/Cache/RedisTaggedCache.php +++ b/src/Illuminate/Cache/RedisTaggedCache.php @@ -193,8 +193,17 @@ protected function flushValues() ->map(fn (string $key) => $this->store->getPrefix().$key) ->chunk(1000); + $connection = $this->store->connection(); foreach ($entries as $cacheKeys) { - $this->store->connection()->del(...$cacheKeys); + if ($connection instanceof PredisClusterConnection) { + $connection->pipeline(function ($connection) use ($cacheKeys) { + foreach ($cacheKeys as $cacheKey) { + $connection->del($cacheKey); + } + }); + } else { + $connection->del(...$cacheKeys); + } } } From a6ab85552f01147d0d40f94fa5f3e69828fd108a Mon Sep 17 00:00:00 2001 From: Vadim Dvorovenko Date: Sat, 8 Nov 2025 21:52:20 +0700 Subject: [PATCH 6/6] [12.x] keys for PredisClusterConnection --- .../Connections/PredisClusterConnection.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Illuminate/Redis/Connections/PredisClusterConnection.php b/src/Illuminate/Redis/Connections/PredisClusterConnection.php index dbf91dc46f77..92212c56df8e 100644 --- a/src/Illuminate/Redis/Connections/PredisClusterConnection.php +++ b/src/Illuminate/Redis/Connections/PredisClusterConnection.php @@ -22,4 +22,20 @@ public function flushdb() $node->executeCommand(tap(new $command)->setArguments(func_get_args())); } } + + /** + * Returns the keys that match a certain pattern. + * + * @param string $pattern + * @return array + */ + public function keys(string $pattern) + { + $keys = []; + foreach ($this->client as $node) { + $keys[] = $node->keys($pattern); + } + + return array_merge(...$keys); + } }