Jenner\SimpleFork\Queue\RedisQueue::get PHP Method

get() public method

get value from the queue
public get ( boolean $block = false ) : boolean | string
$block boolean if block when the queue is empty
return boolean | string
    public function get($block = false)
    {
        if (!$block) {
            return $this->redis->rPop($this->channel);
        } else {
            while (true) {
                $record = $this->redis->rPop($this->channel);
                if ($record === false) {
                    usleep(1000);
                    continue;
                }
                return $record;
            }
        }
    }

Usage Example

 public function testAll()
 {
     if (!extension_loaded("Redis")) {
         $this->markTestSkipped("Redis extension is not loaded");
     }
     $this->queue = new \Jenner\SimpleFork\Queue\RedisQueue();
     $this->assertTrue($this->queue->put('test'));
     $this->assertEquals($this->queue->get(), 'test');
     $this->assertEquals($this->queue->size(), 0);
     $this->queue->close();
 }