RedisDriver::delete()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Thruster\Component\RedisDataCacher;
4
5
use Thruster\Component\DataCacher\DriverInterface;
6
7
/**
8
 * Class RedisDriver
9
 *
10
 * @package Thruster\Component\RedisDataCacher
11
 * @author  Aurimas Niekis <[email protected]>
12
 */
13
class RedisDriver implements DriverInterface
14
{
15
    /**
16
     * @var \Redis
17
     */
18
    protected $redis;
19
20
    /**
21
     * @var int
22
     */
23
    protected $hits;
24
25
    /**
26
     * @var int
27
     */
28
    protected $misses;
29
30 3
    public function __construct($redis)
31
    {
32 3
        $this->redis = $redis;
33 3
        $this->hits = 0;
34 3
        $this->misses = 0;
35 3
    }
36
37
    /**
38
     * @return \Redis
39
     */
40 2
    public function getRedis()
41
    {
42 2
        return $this->redis;
43
    }
44
45
    /**
46
     * @inheritDoc
47
     */
48 1
    public function set(string $key, string $value, int $ttl) : bool
49
    {
50 1
        return $this->getRedis()->set($key, $value, $ttl);
51
    }
52
53
    /**
54
     * @inheritDoc
55
     */
56 2
    public function get(string $key)
57
    {
58 2
        $result = $this->getRedis()->get($key);
59
60 2
        if (false === $result) {
61 1
            $this->misses++;
62
        } else {
63 2
            $this->hits++;
64
        }
65
66 2
        return $result;
67
    }
68
69
    /**
70
     * @inheritDoc
71
     */
72 1
    public function delete(string $key) : bool
73
    {
74 1
        return $this->getRedis()->del($key);
75
    }
76
77
    /**
78
     * @inheritDoc
79
     */
80 1
    public function buildKey(array $parts) : string
81
    {
82 1
        return implode(':', $parts);
83
    }
84
85
    /**
86
     * @inheritDoc
87
     */
88 1
    public function getStatistics() : array
89
    {
90
        return [
91 1
            'hits' => $this->hits,
92 1
            'misses' => $this->misses
93
        ];
94
    }
95
96
}
97