FlintRedisCacheRedis::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

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
namespace Suven\FlintRedis;
3
4
use Predis\Client;
5
6
class FlintRedisCacheRedis implements FlintRedisCache
7
{
8
9
    private $realm;
10
11
    private $predis;
12
13 6
    public function __construct($realm = 'default', $options = [])
14
    {
15 6
        $this->realm = $realm;
16 6
        $this->predis = new Client($options);
17 6
    }
18
19 6
    public function get($key)
20
    {
21 6
        return unserialize($this->predis->hget($this->realm, $key));
22
    }
23
24 3
    public function getAll()
25
    {
26 3
        $values = [];
27
28 3
        foreach ($this->predis->hgetall($this->realm) as $k => $v) {
29 3
            $values[$k] = unserialize($v);
30 2
        }
31
32 3
        return $values;
33
    }
34
35 6
    public function getKeys()
36
    {
37 6
        return $this->predis->hkeys($this->realm);
38
    }
39
40 9
    public function set($key, $value)
41
    {
42 9
        return $this->predis->hset($this->realm, $key, serialize($value));
43
    }
44
45 3
    public function delete($key)
46
    {
47 3
        return $this->predis->hdel($this->realm, $key);
48
    }
49
50 3
    public function flush()
51
    {
52 3
        return $this->predis->hdel($this->realm, $this->getKeys());
53
    }
54
}
55