Last active
May 12, 2016 21:09
-
-
Save samm-git/bad6e0760e74d527a382de9e950ca328 to your computer and use it in GitHub Desktop.
redis health replication role check for the ELB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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