RedisHandler   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 38
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createQueue() 0 4 1
A clear() 0 11 2
A createRedis() 0 8 1
A configure() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Phive Queue package.
5
 *
6
 * (c) Eugene Leonovich <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Phive\Queue\Tests\Handler;
13
14
use Phive\Queue\RedisQueue;
15
16
class RedisHandler extends Handler
17
{
18
    /**
19
     * @var \Redis
20
     */
21
    private $redis;
22
23
    public function createQueue()
24
    {
25
        return new RedisQueue($this->redis);
26
    }
27
28
    public function clear()
29
    {
30
        $this->redis->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_NONE);
31
        $prefix = $this->redis->getOption(\Redis::OPT_PREFIX);
32
        $offset = strlen($prefix);
33
34
        $keys = $this->redis->keys('*');
35
        foreach ($keys as $key) {
36
            $this->redis->del(substr($key, $offset));
37
        }
38
    }
39
40
    public function createRedis()
41
    {
42
        $redis = new \Redis();
43
        $redis->connect($this->getOption('host'), $this->getOption('port'));
44
        $redis->setOption(\Redis::OPT_PREFIX, $this->getOption('prefix'));
45
46
        return $redis;
47
    }
48
49
    protected function configure()
50
    {
51
        $this->redis = $this->createRedis();
52
    }
53
}
54