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);
|
|
|
|
}
|
|
|
|
public function set(string $name, mixed $value): void
|
|
|
|
{
|
2023-10-19 21:49:57 -03:00
|
|
|
$this->client->set($name, $value, 'EX', 60 * 60 * 24);
|
2023-10-19 20:46:52 -03:00
|
|
|
}
|
|
|
|
}
|