コード例 #1
0
 public function dequeue($n = 1, $timeout = 0)
 {
     $n = count($this->list->dequeue($n, $timeout));
     if (!$n) {
         return [];
     }
     return parent::dequeue($n, 0);
 }
コード例 #2
0
 public function shift($n = 1, $timeout = 0)
 {
     $n = count($this->safeQueue->shift($n, $timeout));
     if ($n) {
         return $this->mainQueue->shift($n, 0);
     }
     return [];
 }
コード例 #3
0
 public function test_enqueue_and_dequeue()
 {
     $input = [1, 2, 3];
     $this->queue->enqueue($input);
     $output = $this->queue->dequeue(3);
     $this->assertEquals(array_reverse($input), $output);
 }
コード例 #4
0
 public function test_shifted_items_are_consecutive_when_using_blpop()
 {
     $messageQueue = new Queue($this->redis, 'fifo:message_queue');
     for ($i = 0; $i < 2; $i++) {
         if (!$this->fork()) {
             $items = $this->queue->shift(2, 100);
             if (is_array($items) && count($items) == 2 && $items[1] == $items[0] - 1) {
                 $messageQueue->push(['OK']);
             } else {
                 $messageQueue->push(['ERROR']);
             }
             exit(0);
         }
     }
     sleep($this->childSleep);
     $this->queue->unShift([1, 2, 3, 4]);
     $this->assertEquals(['OK'], $messageQueue->dequeue(1, 100));
     $this->assertEquals(['OK'], $messageQueue->dequeue(1, 100));
 }
コード例 #5
0
 public function test_many_child_processes_can_multipop_from_a_queue_that_will_get_filled_gradually()
 {
     $messageQueue = new Queue($this->redis, 'fifo:message_queue');
     for ($i = 0; $i < 10; $i++) {
         if (!$this->fork()) {
             $items = $this->queue->dequeue(2, 100);
             if (count($items) == 2) {
                 $messageQueue->push([$items[0]->value, $items[1]->value]);
             }
             exit(0);
         }
     }
     sleep($this->childSleep);
     $items = [];
     $now = time();
     for ($i = 0; $i < 10; $i++) {
         $items[] = new PriorityItem($i, $now + $i);
         $items[] = new PriorityItem($i, $now + $i);
     }
     $this->queue->enqueue($items);
     for ($i = 0; $i < 10; $i++) {
         $this->assertCount(2, $messageQueue->dequeue(2, 100));
     }
 }