Files
oficial/app/src/Service/Redis.php

23 lines
550 B
PHP
Raw Normal View History

2023-10-19 20:46:52 -03:00
<?php
namespace Incoviba\Service;
use Predis\Client;
2023-10-19 21:49:57 -03:00
use Incoviba\Common\Implement\Exception\EmptyRedis;
2023-10-19 20:46:52 -03:00
class Redis
{
public function __construct(protected Client $client) {}
public function get(string $name): mixed
{
2023-10-19 21:49:57 -03:00
if (!$this->client->exists($name)) {
throw new EmptyRedis($name);
}
2023-10-19 20:46:52 -03:00
return $this->client->get($name);
}
2023-10-20 19:03:29 -03:00
public function set(string $name, mixed $value, int $expirationTTL = 60 * 60 * 24): void
2023-10-19 20:46:52 -03:00
{
2023-10-20 19:03:29 -03:00
$this->client->set($name, $value, 'EX', $expirationTTL);
2023-10-19 20:46:52 -03:00
}
}