Files
oficial/app/src/Service/Redis.php
aldarien 307f2ac7d7 feature/cierres (#25)
Varios cambios

Co-authored-by: Juan Pablo Vial <jpvialb@incoviba.cl>
Reviewed-on: #25
2025-07-22 13:18:00 +00:00

42 lines
1.1 KiB
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 {
$resolution = 'EX';
if ($expirationTTL === -1) {
$resolution = null;
$expirationTTL = null;
}
$this->client->set($name, $value, $resolution, $expirationTTL);
} catch (ConnectionException) {
return;
}
}
}