Skip to content

Commit e6e0258

Browse files
authored
Merge pull request #141 from laravel/redis
[1.x] Redis adapter improvements
2 parents 25b48ad + 03849dc commit e6e0258

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/Support/RedisAdapter.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ public function xadd(string $key, array $dictionary): string|Pipeline|PhpRedis
4949
*/
5050
public function xrange(string $key, string $start, string $end, int $count = null): array
5151
{
52-
return collect($this->handle([
52+
return collect($this->handle([ // @phpstan-ignore return.type argument.templateType argument.templateType
5353
'XRANGE',
5454
$this->config->get('database.redis.options.prefix').$key,
5555
$start,
5656
$end,
5757
...$count !== null ? ['COUNT', "$count"] : [],
5858
]))->mapWithKeys(fn ($value, $key) => [
59-
$value[0] => collect($value[1])
59+
$value[0] => collect($value[1]) // @phpstan-ignore argument.templateType argument.templateType
6060
->chunk(2)
6161
->map->values()
6262
->mapWithKeys(fn ($value, $key) => [$value[0] => $value[1]])
@@ -74,7 +74,7 @@ public function xtrim(string $key, string $strategy, string $strategyModifier, s
7474
$this->config->get('database.redis.options.prefix').$key,
7575
$strategy,
7676
$strategyModifier,
77-
$threshold,
77+
(string) $threshold,
7878
]);
7979
}
8080

@@ -106,13 +106,15 @@ public function pipeline(callable $closure): array
106106

107107
/**
108108
* Run the given command.
109+
*
110+
* @param list<string> $args
109111
*/
110-
protected function handle($args): mixed
112+
protected function handle(array $args): mixed
111113
{
112114
try {
113115
return tap($this->run($args), function ($result) {
114116
if ($result === false && $this->client() instanceof PhpRedis) {
115-
throw new RedisClientException($this->client()->getLastError());
117+
throw new RedisClientException($this->client()->getLastError() ?? 'An unknown error occurred.');
116118
}
117119
});
118120
} catch (PredisServerException $e) {
@@ -122,13 +124,15 @@ protected function handle($args): mixed
122124

123125
/**
124126
* Run the given command.
127+
*
128+
* @param list<string> $args
125129
*/
126-
protected function run($args): mixed
130+
protected function run(array $args): mixed
127131
{
128132
return match (true) {
129133
$this->client() instanceof PhpRedis => $this->client()->rawCommand(...$args),
130134
$this->client() instanceof Predis,
131-
$this->client() instanceof Pipeline => $this->client()->executeCommand(new RawCommand($args)),
135+
$this->client() instanceof Pipeline => $this->client()->executeCommand(RawCommand::create(...$args)),
132136
};
133137
}
134138

0 commit comments

Comments
 (0)