RedisService::del()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Service;
6
7
use Predis\Client;
8
9
final class RedisService
10
{
11
    public const PROJECT_NAME = 'php-slim-rest-api';
12
13
    public function __construct(private Client $redis)
14 56
    {
15
    }
16 56
17 56
    public function generateKey(string $value): string
18
    {
19 20
        return self::PROJECT_NAME . ':' . $value;
20
    }
21 20
22
    public function exists(string $key): int
23
    {
24 9
        return $this->redis->exists($key);
25
    }
26 9
27
    public function get(string $key): object
28
    {
29 6
        return json_decode($this->redis->get($key));
30
    }
31 6
32
    public function set(string $key, object $value): void
33
    {
34 1
        $this->redis->set($key, json_encode($value));
35
    }
36 1
37 1
    public function setex(string $key, object $value, int $ttl = 3600): void
38
    {
39 7
        $this->redis->setex($key, $ttl, json_encode($value));
40
    }
41 7
42 7
    /**
43
     * @param array<string> $keys
44 3
     */
45
    public function del(array $keys): void
46 3
    {
47 3
        $this->redis->del($keys);
48
    }
49
}
50