mysociety /
theyworkforyou
| 1 | <?php |
||
| 2 | |||
| 3 | namespace MySociety\TheyWorkForYou; |
||
| 4 | |||
| 5 | class Redis extends \Predis\Client { |
||
| 6 | 1 | public function __construct() { |
|
| 7 | 1 | if (REDIS_SENTINELS) { |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 8 | 1 | $sentinels = []; |
|
| 9 | 1 | $sentinel_port = REDIS_SENTINEL_PORT; |
|
|
0 ignored issues
–
show
|
|||
| 10 | 1 | foreach (explode(",", 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, |
||
|
0 ignored issues
–
show
|
|||
| 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 | } |
||
| 39 | 1 | } |
|
| 40 | } |
||
| 41 |