RedisService   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 41
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A generateKey() 0 4 1
A exists() 0 4 1
A get() 0 4 1
A set() 0 4 1
A setex() 0 4 1
A del() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Service;
6
7
class RedisService
8
{
9
    const PROJECT_NAME = 'rest-api-slim-php';
10
11
    protected $redis;
12
13
    public function __construct($redis)
14
    {
15
        $this->redis = $redis;
16
    }
17
18
    public function generateKey($value)
19
    {
20
        return self::PROJECT_NAME . ':' . $value;
21
    }
22
23
    public function exists($key)
24
    {
25
        return $this->redis->exists($key);
26
    }
27
28
    public function get($key)
29
    {
30
        return json_decode($this->redis->get($key), true);
31
    }
32
33
    public function set($key, $value)
34
    {
35
        $this->redis->set($key, json_encode($value));
36
    }
37
38
    public function setex($key, $value, $ttl = 3600)
39
    {
40
        $this->redis->setex($key, $ttl, json_encode($value));
41
    }
42
43
    public function del($key)
44
    {
45
        $this->redis->del($key);
46
    }
47
}
48