Skip to content

Instantly share code, notes, and snippets.

@samm-git
Last active May 12, 2016 21:09
Show Gist options
  • Save samm-git/bad6e0760e74d527a382de9e950ca328 to your computer and use it in GitHub Desktop.
Save samm-git/bad6e0760e74d527a382de9e950ca328 to your computer and use it in GitHub Desktop.
redis health replication role check for the ELB
<?php
// redis test
$r = new Redis();
$r->connect('127.0.0.1', 6379, 2.5); // connect to redis with 2.5 sec timeout
if(!$r) {
header('HTTP/1.1 500 Internal Server Error');
echo "Error: connection failed\n";
exit(0);
}
$repl=$r->info("replication");
if($repl["role"] == "master") {
echo "Redis is ready\n";
exit(0);
}
else {
header('HTTP/1.1 501 Internal Server Error');
echo "Server role is:".$repl["role"]."\n";
exit (0);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment