Skip to content

Commit a7e472f

Browse files
committed
work around predis cluster moved
1 parent 2c57b72 commit a7e472f

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

src/Support/RedisStore.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Redis\Connections\PredisConnection;
99
use Illuminate\Support\Facades\Redis;
1010
use Predis\NotSupportedException;
11+
use Predis\Response\ServerException;
1112
use Throwable;
1213

1314
final class RedisStore
@@ -329,11 +330,24 @@ public function mget(array $keys): array
329330
return $this->withRawValues(function (Connection $connection) use ($keys): array {
330331
if ($connection instanceof PredisClusterConnection) {
331332
$groups = $this->groupByHashTag($keys);
332-
$replies = $connection->pipeline(static function ($pipeline) use ($groups): void {
333-
foreach ($groups as $group) {
334-
$pipeline->mget(...$group);
333+
334+
try {
335+
$replies = $connection->pipeline(static function ($pipeline) use ($groups): void {
336+
foreach ($groups as $group) {
337+
$pipeline->mget(...$group);
338+
}
339+
});
340+
} catch (ServerException $exception) {
341+
if (!str_starts_with($exception->getMessage(), 'MOVED ')) {
342+
throw $exception;
335343
}
336-
});
344+
345+
$replies = array_map(
346+
static fn(array $group): mixed => $connection->command('mget', $group),
347+
$groups,
348+
);
349+
}
350+
337351
$values = [];
338352

339353
foreach ($groups as $groupIndex => $group) {

0 commit comments

Comments
 (0)