public function testGet() { $source = new CM_PagingSource_Redis_List('foo'); $this->assertSame(0, $source->getCount()); $this->assertSame(array(), $source->getItems()); $this->_client->rPush('foo', 'bar1'); $this->_client->rPush('foo', 'bar2'); $this->_client->rPush('foo', 'bar3'); $this->assertSame(3, $source->getCount()); $this->assertSame(array('bar1', 'bar2', 'bar3'), $source->getItems()); $this->assertSame(array('bar2'), $source->getItems(1, 1)); }
public function getItems($offset = null, $count = null) { $cacheKey = array('items', $offset, $count); if (($items = $this->_cacheGet($cacheKey)) === false) { $stop = null; if ($count !== null) { $stop = $offset + $count - 1; } $items = $this->_client->lRange($this->_key, $offset, $stop); $this->_cacheSet($cacheKey, $items); } return $items; }
public function testZRangeByScore() { $key = 'foo'; $this->_client->zAdd($key, 1, 'foo'); $this->_client->zAdd($key, 1.5, 'bar'); $this->_client->zAdd($key, 2, 'foobar'); // normal behaviour $this->assertSame(array('foo', 'bar', 'foobar'), $this->_client->zRangeByScore($key, 1, 2)); // count $this->assertSame(array('foo', 'bar'), $this->_client->zRangeByScore($key, 1, 2, 2)); // offset $this->assertSame(array('bar', 'foobar'), $this->_client->zRangeByScore($key, 1, 2, null, 1)); // withscores $this->assertSame(array('foo' => '1', 'bar' => '1.5', 'foobar' => '2'), $this->_client->zRangeByScore($key, 1, 2, null, null, true)); $this->assertSame(array(), $this->_client->zRangeByScore($key, 1, 2, 0, 0)); }
/** * @runInSeparateProcess * @preserveGlobalState disabled */ public function testPubSubWithClientUsedInSubClosure() { $process = CM_Process::getInstance(); $process->fork(function () { $redisClient = CM_Service_Manager::getInstance()->getRedis(); $clientCount = 0; while ($clientCount == 0) { $clientCount = $redisClient->publish('foo', 'test'); usleep(50 * 1000); } }); $this->_client->set('check', 'bar'); $response = $this->_client->subscribe('foo', function ($channel, $message) { if ($message == 'test') { return [$channel, $message, $this->_client->get('check')]; } else { return false; } }); $this->assertSame(['foo', 'test', 'bar'], $response); $process->waitForChildren(); }
/** * @param string $key * @return string[] */ public function flush($key) { return $this->_redisClient->sFlush($key); }