Wrapper update + Search by music id
This commit is contained in:
parent
fe5c2dc459
commit
4f35d68049
9 changed files with 77 additions and 17 deletions
|
|
@ -5,9 +5,13 @@ class RedisCache {
|
|||
private \Redis $client;
|
||||
function __construct(string $host, int $port, ?string $password) {
|
||||
$this->client = new \Redis();
|
||||
$this->client->connect($host, $port);
|
||||
if (!$this->client->connect($host, $port)) {
|
||||
throw new \Exception('REDIS: Could not connnect to server');
|
||||
}
|
||||
if ($password) {
|
||||
$this->client->auth($password);
|
||||
if (!$this->client->auth($password)) {
|
||||
throw new \Exception('REDIS: Could not authenticate');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -15,12 +19,12 @@ class RedisCache {
|
|||
$this->client->close();
|
||||
}
|
||||
|
||||
public function get(string $cache_key): object|false {
|
||||
if ($this->client->exists($cache_key)) {
|
||||
$data_string = $this->client->get($cache_key);
|
||||
return json_decode($data_string);
|
||||
public function get(string $cache_key): ?object {
|
||||
$data = $this->client->get($cache_key);
|
||||
if ($data) {
|
||||
return json_decode($data);
|
||||
}
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
public function set(string $cache_key, mixed $data, $timeout = 3600) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue