Conditions | 6 |
Paths | 8 |
Total Lines | 32 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Tests | 7 |
CRAP Score | 10.5 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
6 | 1 | public function __construct() { |
|
7 | 1 | if (REDIS_SENTINELS) { |
|
|
|||
8 | 1 | $sentinels = array(); |
|
9 | 1 | $sentinel_port = REDIS_SENTINEL_PORT; |
|
10 | 1 | foreach (REDIS_SENTINELS as $sentinel) { |
|
11 | // Wrap IPv6 addresses in square brackets |
||
12 | 1 | if (filter_var($sentinel, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { |
|
13 | $sentinel = "[${sentinel}]"; |
||
14 | } |
||
15 | 1 | $sentinels[] = "tcp://${sentinel}:{$sentinel_port}?timeout=0.100"; |
|
16 | } |
||
17 | $options = [ |
||
18 | 'replication' => 'sentinel', |
||
19 | 'service' => REDIS_SERVICE_NAME, |
||
20 | 'parameters' => [ |
||
21 | 'database' => REDIS_DB_NUMBER, |
||
22 | ], |
||
23 | ]; |
||
24 | if (REDIS_DB_PASSWORD) { |
||
25 | $options['parameters']['password'] = REDIS_DB_PASSWORD; |
||
26 | } |
||
27 | parent::__construct($sentinels, $options); |
||
28 | } else { |
||
29 | $redis_args = [ |
||
30 | 'host' => REDIS_DB_HOST, |
||
31 | 'port' => REDIS_DB_PORT, |
||
32 | 'db' => REDIS_DB_NUMBER, |
||
33 | ]; |
||
34 | if (REDIS_DB_PASSWORD) { |
||
35 | $redis_args['password'] = REDIS_DB_PASSWORD; |
||
36 | } |
||
37 | parent::__construct($redis_args); |
||
38 | } |
||
41 |