Skip to content

Commit 1478d5e

Browse files
Throw exception when can't ping redis server
1 parent 7d1f21a commit 1478d5e

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"require": {
1515
"php": "~7.1.0 || ~7.2.0",
1616
"ext-redis": "~3.1.6 || ~4.0",
17-
"awonderphp/simplecache": "dev-devel",
17+
"awonderphp/simplecache": "dev-master",
1818
"psr/simple-cache": "^1.0"
1919
},
2020
"require-dev": {

lib/SimpleCacheRedis.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ protected function setRedisObject($obj): bool
4141
if (! $obj instanceof \Redis) {
4242
throw \AWonderPHP\SimpleCache\StrictTypeException::redisConnectorExpected($obj);
4343
}
44+
$test = $obj->ping();
45+
if ($test !== "+PONG") {
46+
throw \AWonderPHP\SimpleCache\InvalidSetupException::pingNoPongRedis();
47+
}
4448
$this->redis = $obj;
4549
return true;
4650
}//end setRedisObject()

lib/SimpleCacheRedisSodium.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ protected function setRedisObject($obj): bool
4141
if (! $obj instanceof \Redis) {
4242
throw \AWonderPHP\SimpleCache\StrictTypeException::redisConnectorExpected($obj);
4343
}
44+
$test = $obj->ping();
45+
if ($test !== "+PONG") {
46+
throw \AWonderPHP\SimpleCache\InvalidSetupException::pingNoPongRedis();
47+
}
4448
$this->redis = $obj;
4549
return true;
4650
}//end setRedisObject()

0 commit comments

Comments
 (0)