Beispiel #1
0
 /**
  * Tests the basic functionality
  */
 public function testBasics()
 {
     $redis = $this->getConnection();
     $set = new ARedisSet("TestSet:" . uniqid(), $redis);
     $this->assertTrue($set->add("fish"));
     $this->assertTrue($set->add("chips"));
     $this->assertEquals(2, $set->getCount());
     $this->assertTrue($set->contains("fish"));
     $this->assertTrue($set->contains("chips"));
     $this->assertTrue($set->remove("fish"));
     $this->assertTrue($set->remove("chips"));
     $this->assertFalse($set->contains("fish"));
     $this->assertFalse($set->contains("chips"));
     $this->assertTrue($set->add("fish"));
     $this->assertTrue($set->add("chips"));
     $this->assertTrue(in_array($set->random(), array("fish", "chips")));
     $this->assertTrue(in_array($set->pop(), array("fish", "chips")));
     $this->assertTrue(in_array($set->pop(), array("fish", "chips")));
     $this->assertFalse($set->contains("fish"));
     $this->assertFalse($set->contains("chips"));
 }
Beispiel #2
0
 /**
  * Remove dead process pids from redis set.
  *
  * @param  \ARedisSet $pool
  * @return integer    amount of dead pids
  */
 protected function checkPidPool(\ARedisSet $pool)
 {
     $removed = 0;
     $pids = $pool->getData(true);
     foreach ($pids as $pid) {
         if ($this->isPidAlive($pid)) {
             continue;
         }
         $pool->remove($pid);
         $removed++;
     }
     return $removed;
 }