Skip to content

Instantly share code, notes, and snippets.

@zircote
Created June 3, 2011 18:49
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 zircote/1006923 to your computer and use it in GitHub Desktop.
Save zircote/1006923 to your computer and use it in GitHub Desktop.
Rediska Worker/Queue Pair for Recurring Tasks
<?php
$options = array('namespace' => 'WorkerProcess_',
'servers' => array(array('host' => '127.0.0.1', 'port' => 6380)));
/* el Jeffe */
$redis = new Rediska($options);
while (true) {
$first_url = $redis->popFromListBlocking(SRC_QUEUE, 0, SRC_QUEUE);
if($first_url){
$redis->appendToList(WORK_QUEUE, $first_url);
}
while (true) {
$next_url = $redis->popFromListBlocking(SRC_QUEUE, 0, SRC_QUEUE);
if ($next_url != $first_url) {
$redis->appendToList(WORK_QUEUE, $next_url);
} else {
break;
}
}
sleep(SLEEP_INTERVAL);
}
<?php
$options = array('namespace' => 'WorkerProcess_',
'servers' => array(array('host' => '127.0.0.1', 'port' => 6380)));
/* el paisano */
$redis = new Rediska($options);
while(true){
$url = $redis->popFromListBlocking(WORK_QUEUE, 0);
$taskResult = someTask($url);
if($taskResult){
echo 'success', PHP_EOL;
} else {
echo 'failure', PHP_EOL;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment