Completed
Push — master ( c1c437...916c2d )
by Sven
24:19
created

FlintRedisCacheRedis::flush()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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
    public function get($key)
20
    {
21
        return unserialize($this->predis->hget($this->realm, $key));
22
    }
23
24
    public function getAll()
25
    {
26
        $values = [];
27
28
        foreach ($this->predis->hgetall($this->realm) as $k => $v) {
29
            $values[$k] = unserialize($v);
30
        }
31
32
        return $values;
33
    }
34
35
    public function getKeys()
36
    {
37
        return $this->predis->hkeys($this->realm);
38
    }
39
40
    public function set($key, $value)
41
    {
42
        return $this->predis->hset($this->realm, $key, serialize($value));
43
    }
44
45
    public function delete($key)
46
    {
47
        return $this->predis->hdel($this->realm, $key);
48
    }
49
50
    public function flush()
51
    {
52
        return $this->predis->hdel($this->realm, $this->getKeys());
53
    }
54
}
55