Skip to content

Instantly share code, notes, and snippets.

Created October 12, 2014 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1867bb9b944511fe7960 to your computer and use it in GitHub Desktop.
Save anonymous/1867bb9b944511fe7960 to your computer and use it in GitHub Desktop.
<?php
function getNextToken() {
$select = null;
$redisKey = 'current_token_id';
$tokenFilename = SYSTEM_DIR.'/tokens_checked.txt';
$file = file($tokenFilename, FILE_SKIP_EMPTY_LINES|FILE_IGNORE_NEW_LINES);
if ($file) {
$fileCount = count($file);
if ($fileCount) {
$redis = new Redis();
//$redis->connect('/tmp/redis.sock');
$redis->connect('127.0.0.1', 6379);
$tokenId = $redis->get($redisKey);
if (!$tokenId OR !isset($file[$tokenId])) {
$tokenId = 0;
}
$select = $file[$tokenId];
$tokenId++;
$redis->set($redisKey, $tokenId);
}
}
return $select;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment