This repository was archived by the owner on Jan 31, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +24
-7
lines changed
src/ZendDiagnostics/Check Expand file tree Collapse file tree 2 files changed +24
-7
lines changed Original file line number Diff line number Diff line change @@ -547,7 +547,7 @@ Validate that a Redis service is running.
547
547
<?php
548
548
use ZendDiagnostics\Check\Redis;
549
549
550
- $redisCheck = new Redis('localhost', 6379);
550
+ $redisCheck = new Redis('localhost', 6379, 'secret' );
551
551
```
552
552
553
553
### SecurityAdvisory
Original file line number Diff line number Diff line change 14
14
*/
15
15
class Redis extends AbstractCheck
16
16
{
17
+ /**
18
+ * @var string|null
19
+ */
20
+ protected $ auth ;
21
+
17
22
/**
18
23
* @var string
19
24
*/
@@ -25,13 +30,15 @@ class Redis extends AbstractCheck
25
30
protected $ port ;
26
31
27
32
/**
28
- * @param string $host
33
+ * @param string $host
29
34
* @param int $port
35
+ * @param string|null $auth
30
36
*/
31
- public function __construct ($ host = 'localhost ' , $ port = 6379 )
37
+ public function __construct ($ host = 'localhost ' , $ port = 6379 , $ auth = null )
32
38
{
33
39
$ this ->host = $ host ;
34
40
$ this ->port = $ port ;
41
+ $ this ->auth = $ auth ;
35
42
}
36
43
37
44
/**
@@ -55,16 +62,26 @@ private function createClient()
55
62
{
56
63
if (class_exists ('\Redis ' )) {
57
64
$ 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
+ }
59
70
60
71
return $ client ;
61
72
}
62
73
63
74
if (class_exists ('Predis\Client ' )) {
64
- return new PredisClient ( array (
75
+ $ parameters = array (
65
76
'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 );
68
85
}
69
86
70
87
throw new \RuntimeException ('Neither the PHP Redis extension or Predis are installed ' );
You can’t perform that action at this time.
0 commit comments