MacFJA / php-redisearch

PHP Client for RediSearch
MIT License
67 stars 9 forks source link

Why the null append? #39

Closed spondec closed 2 years ago

spondec commented 2 years ago

Hi,

I don't understand why appending null to the argument list when there is only one item?

https://github.com/MacFJA/php-redisearch/blob/61eefb6cd84b17beeafc28d0b08270ea52700a16/src/Redis/Client/PhpredisClient.php#L78

A simple FLUSHALL command fails due to the error.

Code:

$redis = new \Redis()
$redis->rawCommand('FLUSHALL'); 

Result:

OK

Code:

$clientFacade = new \MacFJA\RediSearch\Redis\Client\ClientFacade();
$client = $clientFacade->getClient($redis = new \Redis());
$client->executeRaw('FLUSHALL');

Result:

  ErrorException

  Redis::rawcommand(): Raw command arguments must be scalar values!

  at vendor/macfja/redisearch/src/Redis/Client/PhpredisClient.php:81
     77▕         if (count($args) < 2) {
     78▕             $args[] = null;
     79▕         }
     80▕         // @phpstan-ignore-next-line
  ➜  81▕         return $this->redis->rawCommand(...$args);
     82▕     }
     83▕
     84▕     protected function doPipeline(Command ...$commands): array
     85▕     {
MacFJA commented 2 years ago

My bad, I was mislead by the "PhpDoc" that indicate that the function need at least 2 parameters.

But the documentation (and the code) indicate that only the first parameter is mandatory

I will fix it

MacFJA commented 2 years ago

I made a correction and publish a new version (v2.1.2)

It should be better now