Skip to content

Commit

Permalink
Expose error kind on RedisError
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Aug 20, 2023
1 parent 4ef9222 commit a9df23e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/Protocol/RedisError.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ public function unwrap(): never
throw new QueryException($this->message);
}

public function getKind(): ?string
{
$prefix = \strtok($this->message, ' ');

// This is just a convention of Redis server, not part of the protocol
if ($prefix === \strtoupper($prefix)) {
return $prefix;
}

return null;
}

public function getMessage(): string
{
return $this->message;
Expand Down
2 changes: 1 addition & 1 deletion src/RedisClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ public function eval(string $script, array $keys = [], array $args = []): mixed

$response = $this->link->execute('evalsha', [$sha1, \count($keys), ...$keys, ...$args]);

if ($response instanceof RedisError && \strtok($response->getMessage(), ' ') === 'NOSCRIPT') {
if ($response instanceof RedisError && $response->getKind() === 'NOSCRIPT') {
return $this->execute('eval', $script, \count($keys), ...$keys, ...$args);
}

Expand Down

0 comments on commit a9df23e

Please sign in to comment.