Skip to content

Commit

Permalink
fix wrong impletemention
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Lemay committed Sep 2, 2024
1 parent b143f1c commit 8a5dcf2
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions src/Client/PredisClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,16 @@ public function createPersistentConnection(?string $host = null, ?int $port = nu
public function hMSet(string $key, array $data): void
{
if (!$this->redis->hmset(Converter::prefix($key), $data)) {
$this->handleError(__METHOD__, $this->redis->getLastError());
$this->handleError(__METHOD__, $this->getLastError());
}
}

private function getLastError()
{
try {
$this->redis->executeRaw(['INVALID_COMMAND']);
} catch (\Exception $exception) {
return $exception->getMessage();
}
}

Expand All @@ -54,7 +63,7 @@ public function hGetAll(string $key): array
$result = $this->redis->hgetall(Converter::prefix($key));

if ($result === false) {
$this->handleError(__METHOD__, $this->redis->getLastError());
$this->handleError(__METHOD__, $this->getLastError());
}

return $result;
Expand All @@ -68,7 +77,7 @@ public function hget(string $key, string $property): string
$result = $this->redis->hget(Converter::prefix($key), $property);

if (!$result) {
$this->handleError(__METHOD__, $this->redis->getLastError());
$this->handleError(__METHOD__, $this->getLastError());
}

return $result;
Expand All @@ -80,7 +89,7 @@ public function hget(string $key, string $property): string
public function del(string $key): void
{
if (!$this->redis->del(Converter::prefix($key))) {
$this->handleError(__METHOD__, $this->redis->getLastError());
$this->handleError(__METHOD__, $this->getLastError());
}
}

Expand Down Expand Up @@ -118,7 +127,7 @@ public function jsonGetProperty(string $key, string $property): ?string
public function jsonSet(string $key, ?string $path = '$', ?string $value = '{}'): void
{
if (!$this->redis->executeRaw([RedisCommands::JSON_SET->value, Converter::prefix($key), $path, $value])) {
$this->handleError(__METHOD__, $this->redis->getLastError());
$this->handleError(__METHOD__, $this->getLastError());
}
}

Expand All @@ -141,7 +150,7 @@ public function jsonMSet(...$params): void
}

if (!call_user_func_array([$this->redis, 'executeRaw'], [$arguments])) {
$this->handleError(__METHOD__, $this->redis->getLastError());
$this->handleError(__METHOD__, $this->getLastError());
}
}

Expand All @@ -151,7 +160,7 @@ public function jsonMSet(...$params): void
public function jsonDel(string $key, ?string $path = '$'): void
{
if (!$this->redis->executeRaw([RedisCommands::JSON_DELETE->value, Converter::prefix($key), $path])) {
$this->handleError(__METHOD__, $this->redis->getLastError());
$this->handleError(__METHOD__, $this->getLastError());
}
}

Expand Down Expand Up @@ -195,7 +204,7 @@ public function createIndex(string $prefixKey, ?string $format = RedisFormat::HA
}

if (!call_user_func_array([$this->redis, 'executeRaw'], [$arguments])) {
$this->handleError(__METHOD__, $this->redis->getLastError());
$this->handleError(__METHOD__, $this->getLastError());
}
}

Expand Down Expand Up @@ -228,7 +237,7 @@ public function count(string $prefixKey, array $criterias = []): int
$rawResult = call_user_func_array([$this->redis, 'executeRaw'], $arguments);

if (!$rawResult) {
$this->handleError(__METHOD__, $this->redis->getLastError());
$this->handleError(__METHOD__, $this->getLastError());
}

return (int)$rawResult[0];
Expand All @@ -242,7 +251,7 @@ public function scanKeys(string $prefixKey): array
$keys = [];
$iterator = null;
while ($iterator !== 0) {
$scans = $this->redis->scan($iterator, sprintf('%s*', Converter::prefix($prefixKey)));
$scans = $this->redis->scan($iterator, [sprintf('%s*', Converter::prefix($prefixKey))]);
foreach ($scans as $scan) {
$keys[] = $scan;
}
Expand All @@ -256,8 +265,8 @@ public function scanKeys(string $prefixKey): array
*/
public function flushAll(): void
{
if (!$this->redis->flushAll()) {
$this->handleError(__METHOD__, $this->redis->getLastError());
if (!$this->redis->flushall()) {
$this->handleError(__METHOD__, $this->getLastError());
}
}

Expand Down Expand Up @@ -304,7 +313,7 @@ public function search(string $prefixKey, array $search, array $orderBy, ?string
}

if ($result === false) {
$this->handleError(RedisCommands::SEARCH->value, $this->redis->getLastError());
$this->handleError(RedisCommands::SEARCH->value, $this->getLastError());
}

if ($result[0] === 0) {
Expand All @@ -328,7 +337,7 @@ public function customSearch(string $prefixKey, string $query, string $format):
}

if ($result === false) {
$this->handleError(RedisCommands::SEARCH->value, $this->redis->getLastError());
$this->handleError(RedisCommands::SEARCH->value, $this->getLastError());
}

if ($result[0] === 0) {
Expand All @@ -354,7 +363,7 @@ public function searchLike(string $prefixKey, string $search, ?string $format =
}

if ($result === false) {
$this->handleError(RedisCommands::SEARCH->value, $this->redis->getLastError());
$this->handleError(RedisCommands::SEARCH->value, $this->getLastError());
}

if ($result[0] === 0) {
Expand Down

0 comments on commit 8a5dcf2

Please sign in to comment.