Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for Redis info arrays which use Clients and Server keys #60

Open
wants to merge 7 commits into
base: 1.25.x
Choose a base branch
from
31 changes: 26 additions & 5 deletions src/Check/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
use RedisException;
use RuntimeException;

use function array_key_exists;
use function class_exists;
use function is_array;
use function microtime;

/**
Expand Down Expand Up @@ -53,13 +55,32 @@ public function check()
$stats = $client->info();
$responseTime = microtime(true) - $startTime;

$successInformation = [
"responseTime" => $responseTime,
];

if (array_key_exists('connected_clients', $stats)) {
$successInformation['connections'] = (int) $stats['connected_clients'];
} elseif (
array_key_exists('Clients', $stats) &&
is_array($stats['Clients']) &&
array_key_exists('connected_clients', $stats['Clients'])
) {
$successInformation['connections'] = (int) $stats['Clients']['connected_clients'];
}

if (array_key_exists('uptime_in_seconds', $stats)) {
$successInformation['uptime'] = (int) $stats['uptime_in_seconds'];
} elseif (
array_key_exists('Server', $stats) &&
is_array($stats['Server']) && array_key_exists('uptime_in_seconds', $stats['Server'])
) {
$successInformation['uptime'] = (int) $stats['Server']['uptime_in_seconds'];
}

return new Success(
'',
[
"responseTime" => $responseTime,
"connections" => (int) $stats["connected_clients"],
"uptime" => (int) $stats["uptime_in_seconds"],
]
$successInformation
);
}

Expand Down