This repository was archived by the owner on Jan 31, 2020. It is now read-only.
File tree 2 files changed +24
-6
lines changed
src/ZendDiagnostics/Check
2 files changed +24
-6
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
/**
@@ -49,22 +56,33 @@ public function check()
49
56
/**
50
57
* @return PredisClient|RedisExtensionClient
51
58
*
59
+ * @throws \RedisException
52
60
* @throws \RuntimeException
53
61
*/
54
62
private function createClient ()
55
63
{
56
64
if (class_exists ('\Redis ' )) {
57
65
$ client = new RedisExtensionClient ();
58
- $ client ->connect ($ this ->host );
66
+ $ client ->connect ($ this ->host , $ this ->port );
67
+
68
+ if ($ this ->auth && false === $ client ->auth ($ this ->auth )) {
69
+ throw new \RedisException ('Failed to AUTH connection ' );
70
+ }
59
71
60
72
return $ client ;
61
73
}
62
74
63
75
if (class_exists ('Predis\Client ' )) {
64
- return new PredisClient ( array (
76
+ $ parameters = array (
65
77
'host ' => $ this ->host ,
66
78
'port ' => $ this ->port ,
67
- ));
79
+ );
80
+
81
+ if ($ this ->auth ) {
82
+ $ parameters ['password ' ] = $ this ->auth ;
83
+ }
84
+
85
+ return new PredisClient ($ parameters );
68
86
}
69
87
70
88
throw new \RuntimeException ('Neither the PHP Redis extension or Predis are installed ' );
You can’t perform that action at this time.
0 commit comments