23 lines
550 B
PHP
23 lines
550 B
PHP
<?php
|
|
namespace Incoviba\Service;
|
|
|
|
use Predis\Client;
|
|
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
|
|
|
class Redis
|
|
{
|
|
public function __construct(protected Client $client) {}
|
|
|
|
public function get(string $name): mixed
|
|
{
|
|
if (!$this->client->exists($name)) {
|
|
throw new EmptyRedis($name);
|
|
}
|
|
return $this->client->get($name);
|
|
}
|
|
public function set(string $name, mixed $value, int $expirationTTL = 60 * 60 * 24): void
|
|
{
|
|
$this->client->set($name, $value, 'EX', $expirationTTL);
|
|
}
|
|
}
|