當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Pool::addItems方法代碼示例

本文整理匯總了PHP中Pool::addItems方法的典型用法代碼示例。如果您正苦於以下問題:PHP Pool::addItems方法的具體用法?PHP Pool::addItems怎麽用?PHP Pool::addItems使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Pool的用法示例。


在下文中一共展示了Pool::addItems方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testAddItemsSync

 public function testAddItemsSync()
 {
     $pool = new Pool($this->redis, 'test', [Base::OPT_SLAVES_SYNC_ENABLED => true, Base::OPT_SLAVES_SYNC_REQUIRED_COUNT => 5], $this->getTimeMock());
     try {
         $pool->addItems([1, 3, 5, 3]);
     } catch (\PhpRQ\Exception\NotEnoughSlavesSynced $e) {
     }
     $this->assertSame(array_fill_keys(['1', '3', '5'], (string) self::TIME_MOCK), $this->redis->zrange('test', 0, 5, 'WITHSCORES'));
     $this->assertKeys(['test']);
 }
開發者ID:gitter-badger,項目名稱:php-rq,代碼行數:10,代碼來源:PoolSyncTest.php

示例2: testRealUseCaseExample2

 public function testRealUseCaseExample2()
 {
     $message1 = new ExampleMessageObject();
     $message1->int = 1;
     $message1->float = 1.1;
     $message1->string = 'something1';
     $message1->bool = true;
     $message1Serialized = serialize($message1);
     $message2 = new ExampleMessageObject();
     $message2->int = 3;
     $message2->float = 3.3;
     $message2->string = 'something2';
     $message2->bool = false;
     $message2Serialized = serialize($message2);
     $message3 = new ExampleMessageObject();
     $message3->int = 4;
     $message3->float = 4.4;
     $message3->string = 'something3';
     $message3->bool = true;
     $message3Serialized = serialize($message3);
     $message4 = new ExampleMessageObject();
     $message4->int = 5;
     $message4->float = 5.5;
     $message4->string = 'something4';
     $message4->bool = false;
     $message4Serialized = serialize($message4);
     $message5 = new ExampleMessageObject();
     $message5->int = 6;
     $message5->float = 6.6;
     $message5->string = 'something5';
     $message5->bool = true;
     $message5Serialized = serialize($message5);
     $time = time();
     $pool = new Pool($this->redis, 'test');
     $pool->addItems([$message1, $message2, $message3, $message4, $message5]);
     $this->assertSame(5, $this->redis->zcard('test'));
     $items = $this->redis->zrange('test', 0, 10);
     $this->assertTrue(in_array($message1Serialized, $items, true));
     $this->assertTrue(in_array($message2Serialized, $items, true));
     $this->assertTrue(in_array($message3Serialized, $items, true));
     $this->assertTrue(in_array($message4Serialized, $items, true));
     $this->assertTrue(in_array($message5Serialized, $items, true));
     $this->redis->zadd('test', [$message5Serialized => $time + 5]);
     $items = $pool->getItems(3);
     $this->assertSame([$message1Serialized, $message2Serialized, $message3Serialized], $items);
     $pool->ackItem($message1);
     $pool->ackItem($message3);
     $items = $pool->getItems(3);
     $this->assertSame([$message4Serialized], $items);
     $pool->ackItems([$message2Serialized]);
     $this->assertSame(5, $this->redis->zcard('test'));
     $this->assertSame($time + 129600, (int) $this->redis->zscore('test', $message1Serialized));
     $this->assertSame($time + 129600, (int) $this->redis->zscore('test', $message2Serialized));
     $this->assertSame($time + 129600, (int) $this->redis->zscore('test', $message3Serialized));
     $this->assertSame(round($time + 600.1, 1), round($this->redis->zscore('test', $message4Serialized), 1));
     $this->assertSame($time + 5, (int) $this->redis->zscore('test', $message5Serialized));
     $pool->removeItem($message5);
     $this->assertSame(5, $this->redis->zcard('test'));
     $pool->removeItem($message4);
     $this->assertSame(4, $this->redis->zcard('test'));
     $this->assertKeys(['test']);
 }
開發者ID:jannavratil,項目名稱:php-rq,代碼行數:62,代碼來源:PoolTest.php


注:本文中的Pool::addItems方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。