Created
May 2, 2018 10:18
-
-
Save foospidy/5cbadc8eef9c221f52ce5e17c7136577 to your computer and use it in GitHub Desktop.
Example function for checking the count value based on the key of $id in Redis against the value of $limit.
This file contains 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 | |
function api_limit_exceeded($id='nobody', $limit=1500) { | |
$redis = new Redis(); | |
$usage = 0; | |
if($redis->connect($GLOBALS['REDIS_HOST'], $GLOBALS['REDIS_PORT'])) { | |
if($redis->auth($GLOBALS['REDIS_PASSWORD'])) { | |
$usage = $redis->get($id); | |
} else { | |
error_log('Error authenticating to redis!'); | |
} | |
} else { | |
error_log('Error connecting to redis!'); | |
} | |
if($usage > $limit) { | |
return true; | |
} else { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment