當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。