<?php

require 'vendor/autoload.php';
Predis\Autoloader::register();
$client = new Predis\Client(array('host' => '127.0.0.1', 'port' => 6379), array('prefix' => 'php:'));
$client->lpush('blocking:queue', 'first');
$client->lpush('blocking:queue', 'second');
$client->blpop(['blocking:queue'], 0);
# array('php:blocking:queue', 'second')
$client->brpop(['blocking:queue'], 0);
# array('php:blocking:queue', 'first')
$client->rpush('blocking:source', 'message');
$client->brpoplpush('blocking:source', 'blocking:destination', 0);
# 'message'
// Add the job to the high priority queue
$predis->rpush('queue.priority.high', json_encode($job));
// Or, you could add it to the normal or low priority queue.
$predis->rpush('queue.priority.normal', json_encode($job));
$predis->rpush('queue.priority.low', json_encode($job));
/*
 * Simple Continuous While Loop
 */
// Always True
while (1) {
    /* ... perform tasks here ...  */
}
/*
 * Checking the Queue
 */
$job = $predis->blpop('queue.priority.high', 'queue.priority.normal', 'queue.priority.low', 10);
/*
 * Checking to see if a Job was returned
 */
if ($job) {
    // Index 0 of the array holds which queue was returned
    $queue_name = $job[0];
    // Index 1 of the array holds the string value of the job.
    // Since we are passing it JSON, we'll decode it:
    $details = json_decode($job[1]);
    /* ... do job work ... */
}
/* 
 * A Smarter While Statement
 */
// Set the time limit for php to 0 seconds
<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 * Description of list_pop_movement
 *
 * @author changdi
 */
require "../shared.php";
$predis = new Predis\Client($single_server);
//var_dump($predis->rpush('list','item1'));
//var_dump($predis->rpush('list','item2'));
//var_dump($predis->rpush('list2','item3'));
//var_dump($predis->brpoplpush('list2','list',1));
//var_dump($predis->brpoplpush('list2','list',1));
var_dump($predis->brpoplpush('list', 'list2', 1));
var_dump($predis->blpop(['list', 'list2'], 1));
var_dump($predis->blpop(['list', 'list2'], 1));
var_dump($predis->blpop(['list', 'list2'], 1));
var_dump($predis->blpop(['list', 'list2'], 1));
var_dump($predis->lrange('list', 0, -1));
var_dump($predis->lrange('list2', 0, -1));