RedisDriver::getConnection()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 2
nop 1
1
<?php
2
3
namespace yiicod\socketio\drivers;
4
5
use yii\helpers\ArrayHelper;
6
7
/**
8
 * @todo Implement username and password
9
 *
10
 * Class RedisDriver
11
 *
12
 * @package yiicod\socketio\drivers
13
 */
14
class RedisDriver
15
{
16
    public $hostname = 'localhost';
17
18
    public $port = 6379;
19
20
    public $password;
21
    /**
22
     * @var
23
     */
24
    protected $connection;
25
26
    /**
27
     * Get predis connection
28
     *
29
     * @return \Predis\Client
30
     */
31
    public function getConnection($reset = false)
32
    {
33
        if (null === $this->connection || true === $reset) {
34
            $this->connection = new \Predis\Client(ArrayHelper::merge([
35
                'scheme' => 'tcp',
36
                'read_write_timeout' => 0,
37
            ], [
38
                'host' => $this->hostname,
39
                'port' => $this->port,
40
                'password' => $this->password,
41
            ]));
42
        }
43
44
        return $this->connection;
45
    }
46
}
47