You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using a redis cluster the RedisHealthCheck fails. This is due to the fact that a RedisCluster connection requires an argument (which it uses to determine which host in the cluster to ping). An ErrorException is thrown with the following message: RedisCluster::ping() expects at least 1 parameter, 0 given.
Steps To Reproduce
Steps to reproduce the behavior:
You'll need a redis cluster, using redis' built-in clustering mechanism, rather than replicated nodes (i.e. sentinel)
Configure a laravel app to connect to this cluster (snippet 1 below)
Add the RedisHealthCheck to the healthcheck configuration (snippet 2 below)
Hit the healthcheck endpoint
The redis check should report a problem with the following ErrorException: RedisCluster::ping() expects at least 1 parameter, 0 given (screenshot below)
The healthcheck should check whether we're using a cluster connection, and ping each master node.
Possible fixes
I've implemented a custom check in our system to get around this, which checks whether the redis connection (from the facade) is a cluster connection, and if so pings each master node in turn. It may need to account for other scenarios, but I think this will work with most laravel/Lumen installations out of the box.
A couple of considerations to make this more widely applicable:
Configuration for this check, could allow the user to choose specific nodes from the configuration.
Limit the check to a number of nodes
investigate required support for predis (I don't think predis supports clusters at all but i'm not 100%)
<?phpuseException;
useUKFast\HealthCheck\HealthCheck;
useIlluminate\Support\Facades\Redis;
useIlluminate\Redis\Connections\PhpRedisClusterConnection;
classRedisHealthCheckextendsHealthCheck
{
protected$name = 'redis';
publicfunctionstatus()
{
try {
if ($this->isUsingPhpRedis()) {
$this->handlePhpRedisPing();
} else {
// Think this is all we can do for predis?Redis::ping();
}
} catch (Exception$e) {
return$this->problem('Failed to connect to redis', [
'exception' => $this->exceptionContext($e),
]);
}
return$this->okay();
}
protectedfunctionisUsingPhpRedis()
{
return config('database.redis.client') == 'phpredis';
}
protectedfunctionhandlePhpRedisPing()
{
$redis = Redis::connection();
if ($redis instanceof PhpRedisClusterConnection) {
foreach ($redis->_masters() as$master) {
Redis::ping($master);
}
return;
}
$redis->ping();
}
}
I can create a pull request for this, but wanted to make sure I went through an issue first :)
Additional context
~
The text was updated successfully, but these errors were encountered:
What is the issue?
When using a redis cluster the RedisHealthCheck fails. This is due to the fact that a RedisCluster connection requires an argument (which it uses to determine which host in the cluster to ping). An ErrorException is thrown with the following message:
RedisCluster::ping() expects at least 1 parameter, 0 given
.Steps To Reproduce
Steps to reproduce the behavior:
RedisCluster::ping() expects at least 1 parameter, 0 given
(screenshot below)Snippet 1
Snippet 2
Screenshot from postman:
Expected behaviour
The healthcheck should check whether we're using a cluster connection, and ping each master node.
Possible fixes
I've implemented a custom check in our system to get around this, which checks whether the redis connection (from the facade) is a cluster connection, and if so pings each master node in turn. It may need to account for other scenarios, but I think this will work with most laravel/Lumen installations out of the box.
A couple of considerations to make this more widely applicable:
I can create a pull request for this, but wanted to make sure I went through an issue first :)
Additional context
~
The text was updated successfully, but these errors were encountered: