Skip to content

Instantly share code, notes, and snippets.

@foospidy
Created May 2, 2018 10:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foospidy/10b39d0f918f1d7154d314d8334eec55 to your computer and use it in GitHub Desktop.
Save foospidy/10b39d0f918f1d7154d314d8334eec55 to your computer and use it in GitHub Desktop.
Example function for incrementing a counter based on the key of $id in Redis.
<?php
function api_request($id='nobody') {
$redis = new Redis();
if($redis->connect($GLOBALS['REDIS_HOST'], $GLOBALS['REDIS_PORT'])) {
if($redis->auth($GLOBALS['REDIS_PASSWORD'])) {
$redis->incr($id);
} else {
error_log('Error authenticating to redis!');
}
} else {
error_log('Error connecting to redis!');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment