当前位置: 首页>>代码示例>>PHP>>正文


PHP Redis::zRangeByScore方法代码示例

本文整理汇总了PHP中Redis::zRangeByScore方法的典型用法代码示例。如果您正苦于以下问题:PHP Redis::zRangeByScore方法的具体用法?PHP Redis::zRangeByScore怎么用?PHP Redis::zRangeByScore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Redis的用法示例。


在下文中一共展示了Redis::zRangeByScore方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getRequestsSince

 /**
  * @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));
 }
开发者ID:treehouselabs,项目名称:io-bundle,代码行数:12,代码来源:RedisRequestLogger.php

示例2: testDifferentTypeHash

 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));
 }
开发者ID:Jerry-Shaw,项目名称:phpredis,代码行数:56,代码来源:RedisTest.php

示例3: peek

 /**
  * @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);
     });
 }
开发者ID:rybakit,项目名称:taskqueue,代码行数:22,代码来源:RedisQueue.php

示例4: zRangeByScore

 /**
  * @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);
 }
开发者ID:aladin1394,项目名称:CM,代码行数:22,代码来源:Client.php

示例5: Redis

<?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中[每获取一个就删除一个,知道关键词耗尽]
开发者ID:l496501043,项目名称:first,代码行数:31,代码来源:weixin_wz.php

示例6: testZX

 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');
//.........这里部分代码省略.........
开发者ID:0,项目名称:phpredis,代码行数:101,代码来源:TestRedis.php

示例7: testZX

 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');
//.........这里部分代码省略.........
开发者ID:virtulis,项目名称:phpredis,代码行数:101,代码来源:TestRedis.php

示例8: getExpiredJobs

 /**
  * 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);
 }
开发者ID:targetliu,项目名称:phpredis,代码行数:12,代码来源:PHPRedisQueue.php


注:本文中的Redis::zRangeByScore方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。