Skip to content

Commit

Permalink
[11.x] Use null as default cursor value for PHP Redis (#53095)
Browse files Browse the repository at this point in the history
* fix: PHP Redis default cursor value

* remove 0 as default value

* add version check for phpredis 6.1.0 or above
  • Loading branch information
jayan-blutui authored Oct 10, 2024
1 parent 8fbb940 commit 9201b98
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/Illuminate/Cache/RedisStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,15 @@ protected function currentTags($chunkSize = 1000)
default => '',
};

$defaultCursorValue = match (true) {
$connection instanceof PhpRedisConnection && version_compare(phpversion('redis'), '6.1.0', '>=') => 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(
Expand Down
14 changes: 11 additions & 3 deletions src/Illuminate/Cache/RedisTagSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Cache;

use Illuminate\Redis\Connections\PhpRedisConnection;
use Illuminate\Support\Carbon;
use Illuminate\Support\LazyCollection;

Expand Down Expand Up @@ -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 && version_compare(phpversion('redis'), '6.1.0', '>=') => null,
default => '0',
};

return LazyCollection::make(function () use ($connection, $defaultCursorValue) {
foreach ($this->tagIds() as $tagKey) {
$cursor = $defaultCursorValue = '0';
$cursor = $defaultCursorValue;

do {
[$cursor, $entries] = $this->store->connection()->zscan(
[$cursor, $entries] = $connection->zscan(
$this->store->getPrefix().$tagKey,
$cursor,
['match' => '*', 'count' => 1000]
Expand Down

0 comments on commit 9201b98

Please sign in to comment.