Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refacto + handle exceptions #19

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions src/Client/RedisClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,31 +58,33 @@ public function jsonGet(string $key): ?string
$result = $this->redis->rawCommand(RedisCommands::JSON_GET->value, static::convertPrefix($key));

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

return $result;
}

public function jsonSet(string $key, ?string $path = '$', ?string $value = '{}'): ?bool
public function jsonSet(string $key, ?string $path = '$', ?string $value = '{}'): void
{
$result = $this->redis->rawCommand(RedisCommands::JSON_SET->value, static::convertPrefix($key), $path, $value);
if (!$result) {
$this->handleError(RedisCommands::JSON_SET->value, $this->redis->getLastError());
$this->handleError(__METHOD__, $this->redis->getLastError());
}

return true;
}

public function jsonDel(string $key, ?string $path = '$'): ?bool
public function jsonDel(string $key, ?string $path = '$'): void
{
return $this->redis->rawCommand(RedisCommands::JSON_DELETE->value, static::convertPrefix($key), $path);
$result = $this->redis->rawCommand(RedisCommands::JSON_DELETE->value, static::convertPrefix($key), $path);

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

/**
* @param \ReflectionProperty[] $properties
*/
public function createIndex(string $prefixKey, ?string $format = 'HASH', ?array $properties = []): bool
public function createIndex(string $prefixKey, ?string $format = 'HASH', ?array $properties = []): void
{
$prefixKey = static::convertPrefix($prefixKey);

Expand Down Expand Up @@ -126,10 +128,11 @@ public function createIndex(string $prefixKey, ?string $format = 'HASH', ?array
throw new BadPropertyConfigurationException(sprintf("Your class %s does not have any typed property", $prefixKey));
}

/** @var bool $rawResult */
$rawResult = call_user_func_array([$this->redis, 'rawCommand'], $arguments);

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

public function dropIndex(string $prefixKey): bool
Expand All @@ -154,7 +157,11 @@ public function count(string $prefixKey, array $criterias = []): int

$rawResult = call_user_func_array([$this->redis, 'rawCommand'], $arguments);

return (int)$rawResult[0];
if (!$rawResult) {
$this->handleError(__METHOD__, $this->redis->getLastError());
}

return (int) $rawResult[0];
}

public function scanKeys(string $prefixKey): array
Expand Down
6 changes: 3 additions & 3 deletions src/Client/RedisClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public function hMSet(string $key, array $data): void;
public function hGetAll(string $key): array;
public function del(string $key): void;
public function jsonGet(string $key): ?string;
public function jsonSet(string $key, ?string $path = '$', ?string $value = '{}'): ?bool;
public function jsonDel(string $key, ?string $path = '$'): ?bool;
public function createIndex(string $prefixKey, ?string $format = 'HASH', ?array $properties = []): bool;
public function jsonSet(string $key, ?string $path = '$', ?string $value = '{}'): void;
public function jsonDel(string $key, ?string $path = '$'): void;
public function createIndex(string $prefixKey, ?string $format = 'HASH', ?array $properties = []): void;
public function dropIndex(string $prefixKey): bool;
public function count(string $prefixKey, array $criterias = []): int;
public function search(string $prefixKey, array $search, array $orderBy, ?string $format = RedisFormat::HASH->value, ?int $numberOfResults = null): array;
Expand Down
5 changes: 4 additions & 1 deletion src/Om/Converters/AbstractNullConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ abstract class AbstractNullConverter implements ConverterInterface
*/
abstract public function convert($data);

abstract public function revert($data, string $type): mixed;
public function revert($data, string $type): null
{
return null;
}

public function supportsConversion(string $type, mixed $data): bool
{
Expand Down
1 change: 0 additions & 1 deletion src/Om/Converters/HashModel/HashObjectConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Talleu\RedisOm\Om\Converters\HashModel;

use Talleu\RedisOm\Exception\BadPropertyConfigurationException;
use Talleu\RedisOm\Om\Converters\AbstractObjectConverter;
use Talleu\RedisOm\Om\Converters\AbstractDateTimeConverter;
use Talleu\RedisOm\Om\Mapping\Property;
Expand Down
5 changes: 0 additions & 5 deletions src/Om/Converters/HashModel/NullConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,4 @@ public function convert($data): string
{
return 'null';
}

public function revert($data, string $type): mixed
{
return null;
}
}
5 changes: 0 additions & 5 deletions src/Om/Converters/JsonModel/NullConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,4 @@ public function convert($data): null
{
return null;
}

public function revert($data, string $type): mixed
{
return null;
}
}
2 changes: 0 additions & 2 deletions src/Om/Converters/JsonModel/StandardClassConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
namespace Talleu\RedisOm\Om\Converters\JsonModel;

use Talleu\RedisOm\Om\Converters\AbstractStandardClassConverter;
use Talleu\RedisOm\Om\Converters\HashModel\ArrayConverter;
use Talleu\RedisOm\Om\Converters\HashModel\ConverterFactory;
use Talleu\RedisOm\Om\Converters\HashModel\HashObjectConverter;

final class StandardClassConverter extends AbstractStandardClassConverter
{
Expand Down