From 43e68878e4fdc3af50d2d29d0820b3ca49bbde41 Mon Sep 17 00:00:00 2001 From: Jayan Ratna Date: Thu, 10 Oct 2024 11:25:25 +1300 Subject: [PATCH 1/3] fix: PHP Redis default cursor value --- src/Illuminate/Cache/RedisStore.php | 9 +++++++-- src/Illuminate/Cache/RedisTagSet.php | 12 ++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Cache/RedisStore.php b/src/Illuminate/Cache/RedisStore.php index f953d30d5857..1ca03f7c9a7c 100755 --- a/src/Illuminate/Cache/RedisStore.php +++ b/src/Illuminate/Cache/RedisStore.php @@ -292,10 +292,15 @@ protected function currentTags($chunkSize = 1000) default => '', }; + $defaultCursorValue = match (true) { + $connection instanceof PhpRedisConnection => null, + default => '0', + }; + $prefix = $connectionPrefix.$this->getPrefix(); - return LazyCollection::make(function () use ($connection, $chunkSize, $prefix) { - $cursor = $defaultCursorValue = '0'; + return LazyCollection::make(function () use ($connection, $chunkSize, $prefix, $defaultCursorValue) { + $cursor = $defaultCursorValue; do { [$cursor, $tagsChunk] = $connection->scan( diff --git a/src/Illuminate/Cache/RedisTagSet.php b/src/Illuminate/Cache/RedisTagSet.php index 072a01bc2365..3ff9b7e875ec 100644 --- a/src/Illuminate/Cache/RedisTagSet.php +++ b/src/Illuminate/Cache/RedisTagSet.php @@ -2,6 +2,7 @@ namespace Illuminate\Cache; +use Illuminate\Redis\Connections\PhpRedisConnection; use Illuminate\Support\Carbon; use Illuminate\Support\LazyCollection; @@ -35,12 +36,19 @@ public function addEntry(string $key, ?int $ttl = null, $updateWhen = null) */ public function entries() { - return LazyCollection::make(function () { + $connection = $this->store->connection(); + + $defaultCursorValue = match (true) { + $connection instanceof PhpRedisConnection => null, + default => '0', + }; + + return LazyCollection::make(function () use ($connection, $defaultCursorValue) { foreach ($this->tagIds() as $tagKey) { $cursor = $defaultCursorValue = '0'; do { - [$cursor, $entries] = $this->store->connection()->zscan( + [$cursor, $entries] = $connection->zscan( $this->store->getPrefix().$tagKey, $cursor, ['match' => '*', 'count' => 1000] From 7cc844a45f6eea89cf95b9437e62ba41a192a8e2 Mon Sep 17 00:00:00 2001 From: Jayan Ratna Date: Thu, 10 Oct 2024 11:40:49 +1300 Subject: [PATCH 2/3] remove 0 as default value --- src/Illuminate/Cache/RedisTagSet.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Cache/RedisTagSet.php b/src/Illuminate/Cache/RedisTagSet.php index 3ff9b7e875ec..270b5cbd664b 100644 --- a/src/Illuminate/Cache/RedisTagSet.php +++ b/src/Illuminate/Cache/RedisTagSet.php @@ -45,7 +45,7 @@ public function entries() return LazyCollection::make(function () use ($connection, $defaultCursorValue) { foreach ($this->tagIds() as $tagKey) { - $cursor = $defaultCursorValue = '0'; + $cursor = $defaultCursorValue; do { [$cursor, $entries] = $connection->zscan( From f99c4a57be6675569d6debaaa87d514cf118f016 Mon Sep 17 00:00:00 2001 From: Jayan Ratna Date: Thu, 10 Oct 2024 20:17:26 +1300 Subject: [PATCH 3/3] add version check for phpredis 6.1.0 or above --- src/Illuminate/Cache/RedisStore.php | 2 +- src/Illuminate/Cache/RedisTagSet.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Cache/RedisStore.php b/src/Illuminate/Cache/RedisStore.php index 1ca03f7c9a7c..566913389dcb 100755 --- a/src/Illuminate/Cache/RedisStore.php +++ b/src/Illuminate/Cache/RedisStore.php @@ -293,7 +293,7 @@ protected function currentTags($chunkSize = 1000) }; $defaultCursorValue = match (true) { - $connection instanceof PhpRedisConnection => null, + $connection instanceof PhpRedisConnection && version_compare(phpversion('redis'), '6.1.0', '>=') => null, default => '0', }; diff --git a/src/Illuminate/Cache/RedisTagSet.php b/src/Illuminate/Cache/RedisTagSet.php index 270b5cbd664b..c6aea191a83b 100644 --- a/src/Illuminate/Cache/RedisTagSet.php +++ b/src/Illuminate/Cache/RedisTagSet.php @@ -39,7 +39,7 @@ public function entries() $connection = $this->store->connection(); $defaultCursorValue = match (true) { - $connection instanceof PhpRedisConnection => null, + $connection instanceof PhpRedisConnection && version_compare(phpversion('redis'), '6.1.0', '>=') => null, default => '0', };