PHPRedis::setOption()   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 2
crap 1
1
<?php
2
namespace AutoLock\Drivers;
3
4
/**
5
 * This file is part of mmdtl/autolock.
6
 *
7
 * (c) liulu <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the "LICENSE.md"
10
 * file that was distributed with this source code.
11
 */
12
use \Redis;
13
use \RedisException;
14
15
class PHPRedis implements Driver
16
{
17
    /**
18
     * @var Redis
19
     */
20
    private $redis;
21
22 31
    public function __construct(Redis $redis = null)
23
    {
24 31
        if (is_null($redis)) {
25 25
            $this->redis = new Redis();
26
        } else {
27 7
            $this->redis = $redis;
28
        }
29 31
    }
30
31 1
    public function connect($host, $port, $timeout)
32
    {
33 1
        return $this->redis->connect($host, $port, $timeout);
34
    }
35
36 1
    public function set($key, $value, $options = array())
37
    {
38 1
        return $this->redis->set($key, $value, $options);
39
    }
40
41
    /**
42
     * phpunit can't mock function whose name is keyword,so this
43
     * function have no unit test.You should modify carefully.
44
     * @param $script
45
     * @param array $args
46
     * @param int $numKeys
47
     * @return mixed
48
     */
49
    public function evalScript($script, $args = array(), $numKeys = 0)
50
    {
51
        return $this->redis->eval($script, $args, $numKeys);
52
    }
53
54
    /**
55
     * This method will never throw exception, only return false when can't connect with server
56
     * this function will return false or +PONG
57
     * @return mixed
58
     */
59 2
    public function ping()
60
    {
61
        try {
62 2
            $response = $this->redis->ping();
63 1
        } catch (RedisException $e) {
64 1
            $response = false;
65
        }
66 2
        return $response;
67
    }
68
69 1
    public function setOption($key, $value)
70
    {
71 1
        return $this->redis->setOption($key, $value);
72
    }
73
74 25
    public function getPrefixOptionName()
75
    {
76 25
        return Redis::OPT_PREFIX;
77
    }
78
79 1
    public function getInstance()
80
    {
81 1
        return $this->redis;
82
    }
83
}
84