Completed
Push — master ( c1dc9c...606279 )
by Sven
01:47
created

FlintRedisCacheRedis   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 65%

Importance

Changes 0
Metric Value
dl 0
loc 49
c 0
b 0
f 0
wmc 8
lcom 1
cbo 1
ccs 13
cts 20
cp 0.65
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A get() 0 4 1
A getAll() 0 10 2
A getKeys() 0 4 1
A set() 0 4 1
A delete() 0 4 1
A flush() 0 4 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 12
    public function __construct($realm = 'default', $options = [])
14
    {
15 12
        $this->realm = $realm;
16 12
        $this->predis = new Client($options);
17 12
    }
18
19 3
    public function get($key)
20
    {
21 3
        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
            $values[$k] = unserialize($v);
30
        }
31
32
        return $values;
33
    }
34
35 3
    public function getKeys()
36
    {
37 3
        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
    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