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

23 lines
568 B
PHP
Raw Normal View History

2023-10-19 20:46:52 -03:00
<?php
namespace Incoviba\Service;
2024-04-02 13:50:08 -03:00
use Predis\ClientInterface;
2023-10-19 21:49:57 -03:00
use Incoviba\Common\Implement\Exception\EmptyRedis;
2023-10-19 20:46:52 -03:00
class Redis
{
2024-04-02 13:50:08 -03:00
public function __construct(protected ClientInterface $client) {}
2023-10-19 20:46:52 -03:00
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
}
}