Files
oficial/app/src/Service/Redis.php
Juan Pablo Vial 8f16f33a1e Cleanup
2025-03-03 14:57:22 -03:00

37 lines
941 B
PHP

<?php
namespace Incoviba\Service;
use Predis\ClientInterface;
use Incoviba\Common\Implement\Exception\EmptyRedis;
use Predis\Connection\ConnectionException;
class Redis
{
public function __construct(protected ClientInterface $client) {}
/**
* @param string $name
* @return string|null
* @throws EmptyRedis
*/
public function get(string $name): ?string
{
try {
if (!$this->client->exists($name)) {
throw new EmptyRedis($name);
}
return $this->client->get($name);
} catch (ConnectionException $exception) {
throw new EmptyRedis($name, $exception);
}
}
public function set(string $name, mixed $value, int $expirationTTL = 60 * 60 * 24): void
{
try {
$this->client->set($name, $value, 'EX', $expirationTTL);
} catch (ConnectionException) {
return;
}
}
}