/** * @inheritdoc */ public function getRequestsSince(\DateTime $date = null) { $start = $date ? $date->getTimestamp() : '-inf'; $end = time(); return array_map(function ($hash) { list($timestamp, $url) = explode('#', $hash, 2); return [intval($timestamp), $url]; }, $this->redis->zRangeByScore($this->key, $start, $end)); }
public function testDifferentTypeHash() { $key = '{hash}hash'; $dkey = '{hash}hash'; $this->redis->del($key); $this->assertEquals(1, $this->redis->hSet($key, 'key', 'value')); // string I/F $this->assertEquals(FALSE, $this->redis->get($key)); $this->assertEquals(FALSE, $this->redis->getset($key, 'value2')); $this->assertEquals(FALSE, $this->redis->append($key, 'append')); $this->assertEquals(FALSE, $this->redis->getRange($key, 0, 8)); $this->assertEquals(array(FALSE), $this->redis->mget(array($key))); $this->assertEquals(FALSE, $this->redis->incr($key)); $this->assertEquals(FALSE, $this->redis->incrBy($key, 1)); $this->assertEquals(FALSE, $this->redis->decr($key)); $this->assertEquals(FALSE, $this->redis->decrBy($key, 1)); // lists I/F $this->assertEquals(FALSE, $this->redis->rPush($key, 'lvalue')); $this->assertEquals(FALSE, $this->redis->lPush($key, 'lvalue')); $this->assertEquals(FALSE, $this->redis->lLen($key)); $this->assertEquals(FALSE, $this->redis->lPop($key)); $this->assertEquals(FALSE, $this->redis->lrange($key, 0, -1)); $this->assertEquals(FALSE, $this->redis->lTrim($key, 0, 1)); $this->assertEquals(FALSE, $this->redis->lGet($key, 0)); $this->assertEquals(FALSE, $this->redis->lSet($key, 0, "newValue")); $this->assertEquals(FALSE, $this->redis->lrem($key, 'lvalue', 1)); $this->assertEquals(FALSE, $this->redis->lPop($key)); $this->assertEquals(FALSE, $this->redis->rPop($key)); $this->assertEquals(FALSE, $this->redis->rPoplPush($key, $dkey . 'lkey1')); // sets I/F $this->assertEquals(FALSE, $this->redis->sAdd($key, 'sValue1')); $this->assertEquals(FALSE, $this->redis->srem($key, 'sValue1')); $this->assertEquals(FALSE, $this->redis->sPop($key)); $this->assertEquals(FALSE, $this->redis->sMove($key, $dkey . 'skey1', 'sValue1')); $this->assertEquals(FALSE, $this->redis->scard($key)); $this->assertEquals(FALSE, $this->redis->sismember($key, 'sValue1')); $this->assertEquals(FALSE, $this->redis->sInter($key, $dkey . 'skey2')); $this->assertEquals(FALSE, $this->redis->sUnion($key, $dkey . 'skey4')); $this->assertEquals(FALSE, $this->redis->sDiff($key, $dkey . 'skey7')); $this->assertEquals(FALSE, $this->redis->sMembers($key)); $this->assertEquals(FALSE, $this->redis->sRandMember($key)); // sorted sets I/F $this->assertEquals(FALSE, $this->redis->zAdd($key, 1, 'zValue1')); $this->assertEquals(FALSE, $this->redis->zRem($key, 'zValue1')); $this->assertEquals(FALSE, $this->redis->zIncrBy($key, 1, 'zValue1')); $this->assertEquals(FALSE, $this->redis->zRank($key, 'zValue1')); $this->assertEquals(FALSE, $this->redis->zRevRank($key, 'zValue1')); $this->assertEquals(FALSE, $this->redis->zRange($key, 0, -1)); $this->assertEquals(FALSE, $this->redis->zRevRange($key, 0, -1)); $this->assertEquals(FALSE, $this->redis->zRangeByScore($key, 1, 2)); $this->assertEquals(FALSE, $this->redis->zCount($key, 0, -1)); $this->assertEquals(FALSE, $this->redis->zCard($key)); $this->assertEquals(FALSE, $this->redis->zScore($key, 'zValue1')); $this->assertEquals(FALSE, $this->redis->zRemRangeByRank($key, 1, 2)); $this->assertEquals(FALSE, $this->redis->zRemRangeByScore($key, 1, 2)); }
/** * @see AdvancedQueueInterface::peek() */ public function peek($limit = 1, $skip = 0) { if ($limit <= 0) { // Parameter limit must either be -1 or a value greater than or equal 0 throw new \OutOfRangeException('Parameter limit must be greater than 0.'); } if ($skip < 0) { throw new \OutOfRangeException('Parameter skip must be greater than or equal 0.'); } $range = $this->redis->zRangeByScore('tasks', '-inf', time(), array('limit' => array($skip, $limit))); if (empty($range)) { return false; } $serializer = $this->serializer; return new IterableResult($range, function ($data) use($serializer) { $data = substr($data, strpos($data, '@') + 1); return $serializer->unserialize($data); }); }
/** * @param string $key * @param string $start * @param string $end * @param int|null $count * @param int|null $offset * @param boolean|null $returnScore * @return array */ public function zRangeByScore($key, $start, $end, $count = null, $offset = null, $returnScore = null) { $options = array(); if (null !== $count || null !== $offset) { $count = null !== $count ? (int) $count : -1; $offset = null !== $offset ? (int) $offset : 0; $options['limit'] = array($offset, $count); } if ($returnScore) { $options['withscores'] = true; } return $this->_redis->zRangeByScore($key, $start, $end, $options); }
<?php header("Content-type:text/html;charset='utf-8'"); //###################### $redis = new Redis(); $redis->connect('localhost', '6379'); #此处加上验证更安全 $wytypeid = $redis->zRangeByScore('zjseowytypeid', '-inf', '+inf', array('withscores' => false)); //如果为数组为0的话,组件一个0~19的数组,没执行一次sPop随机返回并删除名称为key的set中一个元素 //$redis->DEL('typeid'); if (count($wytypeid) == 0) { for ($i = 0; $i < 10; $i++) { $redis->zAdd('zjseowytypeid', $i, $i); } $wytypeid = $redis->zRangeByScore('zjseowytypeid', '-inf', '+inf', array('withscores' => false)); } $randwytypeid = array_rand($wytypeid); //取得key $lanmu = $wytypeid[$randwytypeid]; //根据key删除值 $redis->zRemRangeByScore('zjseowytypeid', $lanmu, $lanmu); //根据取得要删除的key选择一个相等的值去除 //var_dump($wytypeid);exit; $jkysid = array(47, 48, 49, 50, 51, 52, 53, 54, 55, 56); //这里是对应的织梦后台栏目 //对应10个栏目的id //var_dump($wyurl); $type = $jkysid[$lanmu]; //根据上面取到的得到要插入数据的栏目 //////////////////////////////////////////【获取关键词开始】////////////////////////////////////////////////////// //获取关键词从redis中[每获取一个就删除一个,知道关键词耗尽]
public function testZX() { $this->redis->delete('key'); $this->assertTrue(array() === $this->redis->zRange('key', 0, -1)); $this->assertTrue(array() === $this->redis->zRange('key', 0, -1, true)); $this->assertTrue(1 === $this->redis->zAdd('key', 0, 'val0')); $this->assertTrue(1 === $this->redis->zAdd('key', 2, 'val2')); $this->assertTrue(1 === $this->redis->zAdd('key', 1, 'val1')); $this->assertTrue(1 === $this->redis->zAdd('key', 3, 'val3')); $this->assertTrue(2 === $this->redis->zAdd('key', 4, 'val4', 5, 'val5')); // multiple parameters $this->assertTrue(array('val0', 'val1', 'val2', 'val3', 'val4', 'val5') === $this->redis->zRange('key', 0, -1)); // withscores $ret = $this->redis->zRange('key', 0, -1, true); $this->assertTrue(count($ret) == 6); $this->assertTrue($ret['val0'] == 0); $this->assertTrue($ret['val1'] == 1); $this->assertTrue($ret['val2'] == 2); $this->assertTrue($ret['val3'] == 3); $this->assertTrue($ret['val4'] == 4); $this->assertTrue($ret['val5'] == 5); $this->assertTrue(0 === $this->redis->zDelete('key', 'valX')); $this->assertTrue(1 === $this->redis->zDelete('key', 'val3')); $this->assertTrue(1 === $this->redis->zDelete('key', 'val4')); $this->assertTrue(1 === $this->redis->zDelete('key', 'val5')); $this->assertTrue(array('val0', 'val1', 'val2') === $this->redis->zRange('key', 0, -1)); // zGetReverseRange $this->assertTrue(1 === $this->redis->zAdd('key', 3, 'val3')); $this->assertTrue(1 === $this->redis->zAdd('key', 3, 'aal3')); $zero_to_three = $this->redis->zRangeByScore('key', 0, 3); $this->assertTrue(array('val0', 'val1', 'val2', 'aal3', 'val3') === $zero_to_three || array('val0', 'val1', 'val2', 'val3', 'aal3') === $zero_to_three); $three_to_zero = $this->redis->zRevRangeByScore('key', 3, 0); $this->assertTrue(array_reverse(array('val0', 'val1', 'val2', 'aal3', 'val3')) === $three_to_zero || array_reverse(array('val0', 'val1', 'val2', 'val3', 'aal3')) === $three_to_zero); $this->assertTrue(5 === $this->redis->zCount('key', 0, 3)); // withscores $this->redis->zRemove('key', 'aal3'); $zero_to_three = $this->redis->zRangeByScore('key', 0, 3, array('withscores' => TRUE)); $this->assertTrue(array('val0' => 0, 'val1' => 1, 'val2' => 2, 'val3' => 3) == $zero_to_three); $this->assertTrue(4 === $this->redis->zCount('key', 0, 3)); // limit $this->assertTrue(array('val0') === $this->redis->zRangeByScore('key', 0, 3, array('limit' => array(0, 1)))); $this->assertTrue(array('val0', 'val1') === $this->redis->zRangeByScore('key', 0, 3, array('limit' => array(0, 2)))); $this->assertTrue(array('val1', 'val2') === $this->redis->zRangeByScore('key', 0, 3, array('limit' => array(1, 2)))); $this->assertTrue(array('val0', 'val1') === $this->redis->zRangeByScore('key', 0, 1, array('limit' => array(0, 100)))); $this->assertTrue(array('val3') === $this->redis->zRevRangeByScore('key', 3, 0, array('limit' => array(0, 1)))); $this->assertTrue(array('val3', 'val2') === $this->redis->zRevRangeByScore('key', 3, 0, array('limit' => array(0, 2)))); $this->assertTrue(array('val2', 'val1') === $this->redis->zRevRangeByScore('key', 3, 0, array('limit' => array(1, 2)))); $this->assertTrue(array('val1', 'val0') === $this->redis->zRevRangeByScore('key', 1, 0, array('limit' => array(0, 100)))); $this->assertTrue(4 === $this->redis->zSize('key')); $this->assertTrue(1.0 === $this->redis->zScore('key', 'val1')); $this->assertFalse($this->redis->zScore('key', 'val')); $this->assertFalse($this->redis->zScore(3, 2)); // with () and +inf, -inf $this->redis->delete('zset'); $this->redis->zAdd('zset', 1, 'foo'); $this->redis->zAdd('zset', 2, 'bar'); $this->redis->zAdd('zset', 3, 'biz'); $this->redis->zAdd('zset', 4, 'foz'); $this->assertTrue(array('foo' => 1, 'bar' => 2, 'biz' => 3, 'foz' => 4) == $this->redis->zRangeByScore('zset', '-inf', '+inf', array('withscores' => TRUE))); $this->assertTrue(array('foo' => 1, 'bar' => 2) == $this->redis->zRangeByScore('zset', 1, 2, array('withscores' => TRUE))); $this->assertTrue(array('bar' => 2) == $this->redis->zRangeByScore('zset', '(1', 2, array('withscores' => TRUE))); $this->assertTrue(array() == $this->redis->zRangeByScore('zset', '(1', '(2', array('withscores' => TRUE))); $this->assertTrue(4 == $this->redis->zCount('zset', '-inf', '+inf')); $this->assertTrue(2 == $this->redis->zCount('zset', 1, 2)); $this->assertTrue(1 == $this->redis->zCount('zset', '(1', 2)); $this->assertTrue(0 == $this->redis->zCount('zset', '(1', '(2')); // zincrby $this->redis->delete('key'); $this->assertTrue(1.0 === $this->redis->zIncrBy('key', 1, 'val1')); $this->assertTrue(1.0 === $this->redis->zScore('key', 'val1')); $this->assertTrue(2.5 === $this->redis->zIncrBy('key', 1.5, 'val1')); $this->assertTrue(2.5 === $this->redis->zScore('key', 'val1')); //zUnion $this->redis->delete('key1'); $this->redis->delete('key2'); $this->redis->delete('key3'); $this->redis->delete('keyU'); $this->redis->zAdd('key1', 0, 'val0'); $this->redis->zAdd('key1', 1, 'val1'); $this->redis->zAdd('key2', 2, 'val2'); $this->redis->zAdd('key2', 3, 'val3'); $this->redis->zAdd('key3', 4, 'val4'); $this->redis->zAdd('key3', 5, 'val5'); $this->assertTrue(4 === $this->redis->zUnion('keyU', array('key1', 'key3'))); $this->assertTrue(array('val0', 'val1', 'val4', 'val5') === $this->redis->zRange('keyU', 0, -1)); // Union on non existing keys $this->redis->delete('keyU'); $this->assertTrue(0 === $this->redis->zUnion('keyU', array('X', 'Y'))); $this->assertTrue(array() === $this->redis->zRange('keyU', 0, -1)); // !Exist U Exist → copy of existing zset. $this->redis->delete('keyU', 'X'); $this->assertTrue(2 === $this->redis->zUnion('keyU', array('key1', 'X'))); // test weighted zUnion $this->redis->delete('keyZ'); $this->assertTrue(4 === $this->redis->zUnion('keyZ', array('key1', 'key2'), array(1, 1))); $this->assertTrue(array('val0', 'val1', 'val2', 'val3') === $this->redis->zRange('keyZ', 0, -1)); $this->redis->zDeleteRangeByScore('keyZ', 0, 10); $this->assertTrue(4 === $this->redis->zUnion('keyZ', array('key1', 'key2'), array(5, 1))); $this->assertTrue(array('val0', 'val2', 'val3', 'val1') === $this->redis->zRange('keyZ', 0, -1)); $this->redis->delete('key1'); $this->redis->delete('key2'); $this->redis->delete('key3'); // test integer and float weights (GitHub issue #109). $this->redis->del('key1', 'key2', 'key3'); $this->redis->zadd('key1', 1, 'one'); $this->redis->zadd('key1', 2, 'two'); $this->redis->zadd('key2', 1, 'one'); $this->redis->zadd('key2', 2, 'two'); $this->redis->zadd('key2', 3, 'three'); $this->assertTrue($this->redis->zunion('key3', array('key1', 'key2'), array(2, 3.0)) === 3); $this->redis->delete('key1'); $this->redis->delete('key2'); $this->redis->delete('key3'); // ZREMRANGEBYRANK $this->redis->zAdd('key1', 1, 'one'); $this->redis->zAdd('key1', 2, 'two'); $this->redis->zAdd('key1', 3, 'three'); $this->assertTrue(2 === $this->redis->zremrangebyrank('key1', 0, 1)); $this->assertTrue(array('three' => 3) == $this->redis->zRange('key1', 0, -1, TRUE)); $this->redis->delete('key1'); // zInter $this->redis->zAdd('key1', 0, 'val0'); $this->redis->zAdd('key1', 1, 'val1'); $this->redis->zAdd('key1', 3, 'val3'); $this->redis->zAdd('key2', 2, 'val1'); $this->redis->zAdd('key2', 3, 'val3'); $this->redis->zAdd('key3', 4, 'val3'); $this->redis->zAdd('key3', 5, 'val5'); $this->redis->delete('keyI'); $this->assertTrue(2 === $this->redis->zInter('keyI', array('key1', 'key2'))); $this->assertTrue(array('val1', 'val3') === $this->redis->zRange('keyI', 0, -1)); // Union on non existing keys $this->assertTrue(0 === $this->redis->zInter('keyX', array('X', 'Y'))); $this->assertTrue(array() === $this->redis->zRange('keyX', 0, -1)); // !Exist U Exist $this->assertTrue(0 === $this->redis->zInter('keyY', array('key1', 'X'))); $this->assertTrue(array() === $this->redis->zRange('keyY', 0, -1)); // test weighted zInter $this->redis->delete('key1'); $this->redis->delete('key2'); $this->redis->delete('key3'); $this->redis->zAdd('key1', 0, 'val0'); $this->redis->zAdd('key1', 1, 'val1'); $this->redis->zAdd('key1', 3, 'val3'); $this->redis->zAdd('key2', 2, 'val1'); $this->redis->zAdd('key2', 1, 'val3'); $this->redis->zAdd('key3', 7, 'val1'); $this->redis->zAdd('key3', 3, 'val3'); $this->redis->delete('keyI'); $this->assertTrue(2 === $this->redis->zInter('keyI', array('key1', 'key2'), array(1, 1))); $this->assertTrue(array('val1', 'val3') === $this->redis->zRange('keyI', 0, -1)); $this->redis->delete('keyI'); $this->assertTrue(2 === $this->redis->zInter('keyI', array('key1', 'key2', 'key3'), array(1, 5, 1), 'min')); $this->assertTrue(array('val1', 'val3') === $this->redis->zRange('keyI', 0, -1)); $this->redis->delete('keyI'); $this->assertTrue(2 === $this->redis->zInter('keyI', array('key1', 'key2', 'key3'), array(1, 5, 1), 'max')); $this->assertTrue(array('val3', 'val1') === $this->redis->zRange('keyI', 0, -1)); // zrank, zrevrank $this->redis->delete('z'); $this->redis->zadd('z', 1, 'one'); $this->redis->zadd('z', 2, 'two'); $this->redis->zadd('z', 5, 'five'); $this->assertTrue(0 === $this->redis->zRank('z', 'one')); $this->assertTrue(1 === $this->redis->zRank('z', 'two')); $this->assertTrue(2 === $this->redis->zRank('z', 'five')); $this->assertTrue(2 === $this->redis->zRevRank('z', 'one')); $this->assertTrue(1 === $this->redis->zRevRank('z', 'two')); $this->assertTrue(0 === $this->redis->zRevRank('z', 'five')); }
public function testZX() { $this->redis->delete('key'); $this->assertTrue(array() === $this->redis->zRange('key', 0, -1)); $this->assertTrue(array() === $this->redis->zRange('key', 0, -1, true)); $this->assertTrue(1 === $this->redis->zAdd('key', 0, 'val0')); $this->assertTrue(1 === $this->redis->zAdd('key', 2, 'val2')); $this->assertTrue(1 === $this->redis->zAdd('key', 1, 'val1')); $this->assertTrue(1 === $this->redis->zAdd('key', 3, 'val3')); $this->assertTrue(array('val0', 'val1', 'val2', 'val3') === $this->redis->zRange('key', 0, -1)); // withscores $ret = $this->redis->zRange('key', 0, -1, true); $this->assertTrue(count($ret) == 4); $this->assertTrue($ret['val0'] == 0); $this->assertTrue($ret['val1'] == 1); $this->assertTrue($ret['val2'] == 2); $this->assertTrue($ret['val3'] == 3); $this->assertTrue(0 === $this->redis->zDelete('key', 'valX')); $this->assertTrue(1 === $this->redis->zDelete('key', 'val3')); $this->assertTrue(array('val0', 'val1', 'val2') === $this->redis->zRange('key', 0, -1)); // zGetReverseRange $this->assertTrue(1 === $this->redis->zAdd('key', 3, 'val3')); $this->assertTrue(1 === $this->redis->zAdd('key', 3, 'aal3')); $zero_to_three = $this->redis->zRangeByScore('key', 0, 3); $this->assertTrue(array('val0', 'val1', 'val2', 'aal3', 'val3') === $zero_to_three || array('val0', 'val1', 'val2', 'val3', 'aal3') === $zero_to_three); $this->assertTrue(5 === $this->redis->zCount('key', 0, 3)); // withscores $this->redis->zRemove('key', 'aal3'); $zero_to_three = $this->redis->zRangeByScore('key', 0, 3, array('withscores' => TRUE)); $this->assertTrue(array('val0' => 0, 'val1' => 1, 'val2' => 2, 'val3' => 3) == $zero_to_three); $this->assertTrue(4 === $this->redis->zCount('key', 0, 3)); // limit $this->assertTrue(array('val0') === $this->redis->zRangeByScore('key', 0, 3, array('limit' => array(0, 1)))); $this->assertTrue(array('val0', 'val1') === $this->redis->zRangeByScore('key', 0, 3, array('limit' => array(0, 2)))); $this->assertTrue(array('val1', 'val2') === $this->redis->zRangeByScore('key', 0, 3, array('limit' => array(1, 2)))); $this->assertTrue(array('val0', 'val1') === $this->redis->zRangeByScore('key', 0, 1, array('limit' => array(0, 100)))); $this->assertTrue(4 === $this->redis->zSize('key')); $this->assertTrue(1.0 === $this->redis->zScore('key', 'val1')); $this->assertFalse($this->redis->zScore('key', 'val')); $this->assertFalse($this->redis->zScore(3, 2)); // zincrby $this->redis->delete('key'); $this->assertTrue(1.0 === $this->redis->zIncrBy('key', 1, 'val1')); $this->assertTrue(1.0 === $this->redis->zScore('key', 'val1')); $this->assertTrue(2.5 === $this->redis->zIncrBy('key', 1.5, 'val1')); $this->assertTrue(2.5 === $this->redis->zScore('key', 'val1')); //zUnion $this->redis->delete('key1'); $this->redis->delete('key2'); $this->redis->delete('key3'); $this->redis->delete('keyU'); $this->redis->zAdd('key1', 0, 'val0'); $this->redis->zAdd('key1', 1, 'val1'); $this->redis->zAdd('key2', 2, 'val2'); $this->redis->zAdd('key2', 3, 'val3'); $this->redis->zAdd('key3', 4, 'val4'); $this->redis->zAdd('key3', 5, 'val5'); $this->assertTrue(4 === $this->redis->zUnion('keyU', array('key1', 'key3'))); $this->assertTrue(array('val0', 'val1', 'val4', 'val5') === $this->redis->zRange('keyU', 0, -1)); // Union on non existing keys $this->redis->delete('keyU'); $this->assertTrue(0 === $this->redis->zUnion('keyU', array('X', 'Y'))); $this->assertTrue(array() === $this->redis->zRange('keyU', 0, -1)); // !Exist U Exist $this->redis->delete('keyU'); $this->assertTrue(2 === $this->redis->zUnion('keyU', array('key1', 'X'))); $this->assertTrue($this->redis->zRange('key1', 0, -1) === $this->redis->zRange('keyU', 0, -1)); // test weighted zUnion $this->redis->delete('keyZ'); $this->assertTrue(4 === $this->redis->zUnion('keyZ', array('key1', 'key2'), array(1, 1))); $this->assertTrue(array('val0', 'val1', 'val2', 'val3') === $this->redis->zRange('keyZ', 0, -1)); $this->redis->zDeleteRangeByScore('keyZ', 0, 10); $this->assertTrue(4 === $this->redis->zUnion('keyZ', array('key1', 'key2'), array(5, 1))); $this->assertTrue(array('val0', 'val2', 'val3', 'val1') === $this->redis->zRange('keyZ', 0, -1)); $this->redis->delete('key1'); $this->redis->delete('key2'); $this->redis->delete('key3'); // zInter $this->redis->zAdd('key1', 0, 'val0'); $this->redis->zAdd('key1', 1, 'val1'); $this->redis->zAdd('key1', 3, 'val3'); $this->redis->zAdd('key2', 2, 'val1'); $this->redis->zAdd('key2', 3, 'val3'); $this->redis->zAdd('key3', 4, 'val3'); $this->redis->zAdd('key3', 5, 'val5'); $this->redis->delete('keyI'); $this->assertTrue(2 === $this->redis->zInter('keyI', array('key1', 'key2'))); $this->assertTrue(array('val1', 'val3') === $this->redis->zRange('keyI', 0, -1)); // Union on non existing keys $this->assertTrue(0 === $this->redis->zInter('keyX', array('X', 'Y'))); $this->assertTrue(array() === $this->redis->zRange('keyX', 0, -1)); // !Exist U Exist $this->assertTrue(0 === $this->redis->zInter('keyY', array('key1', 'X'))); $this->assertTrue(array() === $this->redis->zRange('keyY', 0, -1)); // test weighted zInter $this->redis->delete('key1'); $this->redis->delete('key2'); $this->redis->delete('key3'); $this->redis->zAdd('key1', 0, 'val0'); $this->redis->zAdd('key1', 1, 'val1'); $this->redis->zAdd('key1', 3, 'val3'); $this->redis->zAdd('key2', 2, 'val1'); $this->redis->zAdd('key2', 1, 'val3'); $this->redis->zAdd('key3', 7, 'val1'); $this->redis->zAdd('key3', 3, 'val3'); $this->redis->delete('keyI'); $this->assertTrue(2 === $this->redis->zInter('keyI', array('key1', 'key2'), array(1, 1))); $this->assertTrue(array('val1', 'val3') === $this->redis->zRange('keyI', 0, -1)); $this->redis->delete('keyI'); $this->assertTrue(2 === $this->redis->zInter('keyI', array('key1', 'key2', 'key3'), array(1, 5, 1), 'min')); $this->assertTrue(array('val1', 'val3') === $this->redis->zRange('keyI', 0, -1)); $this->redis->delete('keyI'); $this->assertTrue(2 === $this->redis->zInter('keyI', array('key1', 'key2', 'key3'), array(1, 5, 1), 'max')); $this->assertTrue(array('val3', 'val1') === $this->redis->zRange('keyI', 0, -1)); // zrevrange $this->redis->delete('z'); $this->redis->zadd('z', 1, 'one'); $this->redis->zadd('z', 2, 'two'); $this->redis->zadd('z', 5, 'five'); $this->redis->zadd('z', 10, 'ten'); $this->assertTrue(array('ten') === $this->redis->zReverseRange('z', 0, 0)); $this->assertTrue(array('ten', 'five', 'two') === $this->redis->zReverseRange('z', 0, 2)); $this->assertTrue(array('five', 'two') === $this->redis->zReverseRange('z', 1, 2)); $this->assertTrue(array('five') === $this->redis->zReverseRange('z', 1, 1)); $this->assertTrue(array() === $this->redis->zReverseRange('z', 1, 0)); $this->assertTrue(array() === $this->redis->zReverseRange('z', -1, 0)); // zrank, zrevrank $this->redis->delete('z'); $this->redis->zadd('z', 1, 'one'); $this->redis->zadd('z', 2, 'two'); $this->redis->zadd('z', 5, 'five'); $this->assertTrue(0 === $this->redis->zRank('z', 'one')); $this->assertTrue(1 === $this->redis->zRank('z', 'two')); $this->assertTrue(2 === $this->redis->zRank('z', 'five')); $this->assertTrue(2 === $this->redis->zRevRank('z', 'one')); $this->assertTrue(1 === $this->redis->zRevRank('z', 'two')); $this->assertTrue(0 === $this->redis->zRevRank('z', 'five')); }
/** * Get the expired jobs from a given queue. * * @param \Redis $transaction * @param string $from * @param int $time * @return array */ protected function getExpiredJobs($transaction, $from, $time) { return $transaction->zRangeByScore($from, '-inf', $time); }