Skip to content

Commit 7f7a6f7

Browse files
committed
Improve RedisRepository chunk method
Ensures chunk count is at least 1, uses static closure for key mapping, compares cursor as string, and sets default prefix to empty string for better reliability and consistency
1 parent eb72b8c commit 7f7a6f7

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/Repositories/RedisRepository.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public function exists(string $hash): bool
3131
*/
3232
public function chunk(string $pattern, int $count): Generator
3333
{
34+
$count = max(1, $count);
35+
3436
[$cursor, $prefix] = array_values($this->getScanParameters());
3537

3638
do {
@@ -53,10 +55,10 @@ public function chunk(string $pattern, int $count): Generator
5355
continue;
5456
}
5557

56-
yield array_map(function (string $key) use ($prefix) {
58+
yield array_map(static function (string $key) use ($prefix) {
5759
return Str::after($key, $prefix);
5860
}, $keys);
59-
} while ($cursor !== '0');
61+
} while ((string) $cursor !== '0');
6062
}
6163

6264
/**
@@ -75,7 +77,7 @@ protected function getScanParameters(): array
7577
],
7678
default => [
7779
'cursor' => null,
78-
'prefix' => null,
80+
'prefix' => '',
7981
]
8082
};
8183
}

0 commit comments

Comments
 (0)