Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit 5b25f6f

Browse files
committed
Added redis auth parameter
1 parent 6ffffbe commit 5b25f6f

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ Validate that a Redis service is running.
547547
<?php
548548
use ZendDiagnostics\Check\Redis;
549549

550-
$redisCheck = new Redis('localhost', 6379);
550+
$redisCheck = new Redis('localhost', 6379, 'secret');
551551
```
552552

553553
### SecurityAdvisory

src/ZendDiagnostics/Check/Redis.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
*/
1515
class Redis extends AbstractCheck
1616
{
17+
/**
18+
* @var string|null
19+
*/
20+
protected $auth;
21+
1722
/**
1823
* @var string
1924
*/
@@ -25,13 +30,15 @@ class Redis extends AbstractCheck
2530
protected $port;
2631

2732
/**
28-
* @param string $host
33+
* @param string $host
2934
* @param int $port
35+
* @param string|null $auth
3036
*/
31-
public function __construct($host = 'localhost', $port = 6379)
37+
public function __construct($host = 'localhost', $port = 6379, $auth = null)
3238
{
3339
$this->host = $host;
3440
$this->port = $port;
41+
$this->auth = $auth;
3542
}
3643

3744
/**
@@ -55,16 +62,26 @@ private function createClient()
5562
{
5663
if (class_exists('\Redis')) {
5764
$client = new RedisExtensionClient();
58-
$client->connect($this->host);
65+
$client->connect($this->host, $this->port);
66+
67+
if ($this->auth) {
68+
$client->auth($this->auth);
69+
}
5970

6071
return $client;
6172
}
6273

6374
if (class_exists('Predis\Client')) {
64-
return new PredisClient(array(
75+
$parameters = array(
6576
'host' => $this->host,
66-
'port' => $this->port,
67-
));
77+
'port' => $this->port
78+
);
79+
80+
if ($this->auth) {
81+
$parameters['password'] = $this->auth;
82+
}
83+
84+
return new PredisClient($parameters);
6885
}
6986

7087
throw new \RuntimeException('Neither the PHP Redis extension or Predis are installed');

0 commit comments

Comments
 (0)