Skip to content

Commit

Permalink
Add support for phpredis RedisCluster types
Browse files Browse the repository at this point in the history
  • Loading branch information
jessarcher committed Mar 15, 2024
1 parent 0737828 commit 5d10ec7
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Support/RedisAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Predis\Pipeline\Pipeline;
use Predis\Response\ServerException as PredisServerException;
use Redis as PhpRedis;
use RedisCluster as PhpRedisCluster;

/**
* @internal
Expand Down Expand Up @@ -113,7 +114,7 @@ protected function handle(array $args): mixed
{
try {
return tap($this->run($args), function ($result) use ($args) {
if ($result === false && $this->client() instanceof PhpRedis) {
if ($result === false && ($this->client() instanceof PhpRedis || $this->client() instanceof PhpRedisCluster)) {
throw RedisServerException::whileRunningCommand(implode(' ', $args), $this->client()->getLastError() ?? 'An unknown error occurred.');
}
});
Expand All @@ -130,7 +131,8 @@ protected function handle(array $args): mixed
protected function run(array $args): mixed
{
return match (true) {
$this->client() instanceof PhpRedis => $this->client()->rawCommand(...$args),
$this->client() instanceof PhpRedis,
$this->client() instanceof PhpRedisCluster => $this->client()->rawCommand(...$args),
$this->client() instanceof Predis,
$this->client() instanceof Pipeline => $this->client()->executeCommand(RawCommand::create(...$args)),
};
Expand All @@ -139,7 +141,7 @@ protected function run(array $args): mixed
/**
* Retrieve the Redis client.
*/
protected function client(): PhpRedis|Predis|Pipeline
protected function client(): PhpRedis|Predis|Pipeline|PhpRedisCluster
{
return $this->client ?? $this->connection->client();
}
Expand Down

0 comments on commit 5d10ec7

Please sign in to comment.