Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save foospidy/5cbadc8eef9c221f52ce5e17c7136577 to your computer and use it in GitHub Desktop.
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.
<?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