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

Commit 07b6a7a

Browse files
committed
Merge pull request #52 from kbond/php-redis
Added support for php redis extension
2 parents 6f9d8ff + d6185b8 commit 07b6a7a

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

src/ZendDiagnostics/Check/Redis.php

+26-12
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
namespace ZendDiagnostics\Check;
77

8-
use Predis\Client;
9-
use ZendDiagnostics\Result\Failure;
8+
use Predis\Client as PredisClient;
9+
use Redis as RedisExtensionClient;
1010
use ZendDiagnostics\Result\Success;
1111

1212
/**
@@ -38,21 +38,35 @@ public function __construct($host = 'localhost', $port = 6379)
3838
* Perform the check
3939
*
4040
* @see \ZendDiagnostics\Check\CheckInterface::check()
41-
* @return Failure|Success
4241
*/
4342
public function check()
4443
{
45-
if (!class_exists('Predis\Client')) {
46-
return new Failure('Predis is not installed');
47-
}
44+
$this->createClient()->ping();
45+
46+
return new Success();
47+
}
48+
49+
/**
50+
* @return PredisClient|RedisExtensionClient
51+
*
52+
* @throws \RuntimeException
53+
*/
54+
private function createClient()
55+
{
56+
if (class_exists('\Redis')) {
57+
$client = new RedisExtensionClient();
58+
$client->connect($this->host);
4859

49-
$client = new Client(array(
50-
'host' => $this->host,
51-
'port' => $this->port,
52-
));
60+
return $client;
61+
}
5362

54-
$client->ping();
63+
if (class_exists('Predis\Client')) {
64+
return new PredisClient(array(
65+
'host' => $this->host,
66+
'port' => $this->port,
67+
));
68+
}
5569

56-
return new Success();
70+
throw new \RuntimeException('Neither the PHP Redis extension or Predis are installed');
5771
}
5872
}

tests/ZendDiagnosticsTest/ChecksTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function testRedis()
6363
$this->assertInstanceOf('ZendDiagnostics\Result\Success', $result);
6464

6565
$check = new Redis('127.0.0.250', 9999);
66-
$this->setExpectedException('Predis\Connection\ConnectionException');
66+
$this->setExpectedException('\Exception');
6767
$check->check();
6868
}
6969

0 commit comments

Comments
 (0)