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


PHP Redis::zadd方法代码示例

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


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

示例1: save

 public function save()
 {
     if (!$this->id) {
         return false;
     }
     $args = Util::array_to_multibulk($this->encodeFields());
     $args['id'];
     call_user_func_array(array('Redis', 'hmset'), array_merge(array($this->key()), $args));
     Redis::zadd(get_class($this), microtime(true), $this->id);
 }
开发者ID:nickyleach,项目名称:OSTSurvey,代码行数:10,代码来源:RedisObject.php

示例2: state

 /**
  * Change state
  *
  * @param $state
  * @return $this
  */
 public function state($state)
 {
     $this->emit($state);
     $this->removeState();
     // Keep "FIFO!"
     $score = $this->injectors['timing'] + $this->injectors['priority'];
     $this->set('state', $state);
     $this->client->zadd('q:jobs', $score, $this->injectors['id']);
     $this->client->zadd('q:jobs:' . $state, $score, $this->injectors['id']);
     $this->client->zadd('q:jobs:' . $this->injectors['type'] . ':' . $state, $score, $this->injectors['id']);
     // Set inactive job to waiting list
     if ($this->queue->originalMode() && 'inactive' == $state) {
         $this->client->lpush('q:' . $this->injectors['type'] . ':jobs', 1);
     }
     $this->set('updated_at', Util::now());
     return $this;
 }
开发者ID:coderofsalvation,项目名称:php-kue,代码行数:23,代码来源:Job.php

示例3: sequence


//.........这里部分代码省略.........
     $this->assertTrue(count($ret[$i++]) === 3);
     $this->assertTrue($ret[$i++] === array('sValue1'));
     // intersection
     $this->assertTrue($ret[$i++] === 1);
     // intersection + store → 1 value in the destination set.
     $this->assertTrue($ret[$i++] === array('sValue1'));
     // sinterstore destination contents
     foreach (array('sValue1', 'sValue2', 'sValue4') as $k) {
         // (skeydest U sKey2) contains sValue1, sValue2, and sValue4.
         $this->assertTrue(in_array($k, $ret[$i]));
     }
     $this->assertTrue(count($ret[$i++]) === 3);
     // union size
     $this->assertTrue($ret[$i++] === 3);
     // unionstore size
     foreach (array('sValue1', 'sValue2', 'sValue4') as $k) {
         // (skeyUnion) contains sValue1, sValue2, and sValue4.
         $this->assertTrue(in_array($k, $ret[$i]));
     }
     $this->assertTrue(count($ret[$i++]) === 3);
     // skeyUnion size
     $this->assertTrue($ret[$i++] === array('sValue3'));
     // diff skey1, skey2 : only sValue3 is not shared.
     $this->assertTrue($ret[$i++] === 1);
     // sdiffstore size == 1
     $this->assertTrue($ret[$i++] === array('sValue3'));
     // contents of sDiffDest
     $this->assertTrue(in_array($ret[$i++], array('sValue1', 'sValue2', 'sValue4')));
     // we removed an element from sKey2
     $this->assertTrue($ret[$i++] === 2);
     // sKey2 now has 2 elements only.
     $this->assertTrue(count($ret) === $i);
     // sorted sets
     $ret = $this->redis->multi($mode)->delete('zkey1', 'zkey2', 'zkey5', 'zInter', 'zUnion')->zadd('zkey1', 1, 'zValue1')->zadd('zkey1', 5, 'zValue5')->zadd('zkey1', 2, 'zValue2')->zRange('zkey1', 0, -1)->zDelete('zkey1', 'zValue2')->zRange('zkey1', 0, -1)->zadd('zkey1', 11, 'zValue11')->zadd('zkey1', 12, 'zValue12')->zadd('zkey1', 13, 'zValue13')->zadd('zkey1', 14, 'zValue14')->zadd('zkey1', 15, 'zValue15')->zDeleteRangeByScore('zkey1', 11, 13)->zrange('zkey1', 0, -1)->zReverseRange('zkey1', 0, -1)->zRangeByScore('zkey1', 1, 6)->zCard('zkey1')->zScore('zkey1', 'zValue15')->zadd('zkey2', 5, 'zValue5')->zadd('zkey2', 2, 'zValue2')->zInter('zInter', array('zkey1', 'zkey2'))->zRange('zkey1', 0, -1)->zRange('zkey2', 0, -1)->zRange('zInter', 0, -1)->zUnion('zUnion', array('zkey1', 'zkey2'))->zRange('zUnion', 0, -1)->zadd('zkey5', 5, 'zValue5')->zIncrBy('zkey5', 3, 'zValue5')->zScore('zkey5', 'zValue5')->zScore('zkey5', 'unknown')->exec();
     $i = 0;
     $this->assertTrue(is_array($ret));
     $this->assertTrue(is_long($ret[$i]) && $ret[$i] >= 0 && $ret[$i] <= 5);
     $i++;
     // deleting at most 5 keys
     $this->assertTrue($ret[$i++] === 1);
     $this->assertTrue($ret[$i++] === 1);
     $this->assertTrue($ret[$i++] === 1);
     $this->assertTrue($ret[$i++] === array('zValue1', 'zValue2', 'zValue5'));
     $this->assertTrue($ret[$i++] === 1);
     $this->assertTrue($ret[$i++] === array('zValue1', 'zValue5'));
     $this->assertTrue($ret[$i++] === 1);
     // adding zValue11
     $this->assertTrue($ret[$i++] === 1);
     // adding zValue12
     $this->assertTrue($ret[$i++] === 1);
     // adding zValue13
     $this->assertTrue($ret[$i++] === 1);
     // adding zValue14
     $this->assertTrue($ret[$i++] === 1);
     // adding zValue15
     $this->assertTrue($ret[$i++] === 3);
     // deleted zValue11, zValue12, zValue13
     $this->assertTrue($ret[$i++] === array('zValue1', 'zValue5', 'zValue14', 'zValue15'));
     $this->assertTrue($ret[$i++] === array('zValue15', 'zValue14', 'zValue5', 'zValue1'));
     $this->assertTrue($ret[$i++] === array('zValue1', 'zValue5'));
     $this->assertTrue($ret[$i++] === 4);
     // 4 elements
     $this->assertTrue($ret[$i++] === 15.0);
     $this->assertTrue($ret[$i++] === 1);
     // added value
     $this->assertTrue($ret[$i++] === 1);
开发者ID:stonegithubs,项目名称:phpredis,代码行数:67,代码来源:TestRedis.php

示例4: testZScan

 public function testZScan()
 {
     if (version_compare($this->version, "2.8.0", "lt")) {
         $this->markTestSkipped();
         return;
     }
     $this->redis->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY);
     $this->redis->del('zset');
     $i_tot_score = 0;
     $i_p_score = 0;
     $i_p_count = 0;
     for ($i = 0; $i < 2000; $i++) {
         if ($i < 10) {
             $this->redis->zadd('zset', $i, "pmem:{$i}");
             $i_p_score += $i;
             $i_p_count += 1;
         } else {
             $this->redis->zadd('zset', $i, "mem:{$i}");
         }
         $i_tot_score += $i;
     }
     // Scan them all
     $it = NULL;
     while ($arr_keys = $this->redis->zscan('zset', $it)) {
         foreach ($arr_keys as $str_mem => $f_score) {
             $i_tot_score -= $f_score;
             $i--;
         }
     }
     $this->assertEquals(0, $i);
     $this->assertEquals(0, $i_tot_score);
     // Just scan "pmem" members
     $it = NULL;
     $i_p_score_old = $i_p_score;
     $i_p_count_old = $i_p_count;
     while ($arr_keys = $this->redis->zscan('zset', $it, "*pmem*")) {
         foreach ($arr_keys as $str_mem => $f_score) {
             $i_p_score -= $f_score;
             $i_p_count -= 1;
         }
     }
     $this->assertEquals(0, $i_p_score);
     $this->assertEquals(0, $i_p_count);
     // Turn off retrying and we should get some empty results
     $this->redis->setOption(Redis::OPT_SCAN, Redis::SCAN_NORETRY);
     $i_skips = 0;
     $i_p_score = $i_p_score_old;
     $i_p_count = $i_p_count_old;
     $it = NULL;
     while (($arr_keys = $this->redis->zscan('zset', $it, "*pmem*")) !== FALSE) {
         if (count($arr_keys) == 0) {
             $i_skips++;
         }
         foreach ($arr_keys as $str_mem => $f_score) {
             $i_p_score -= $f_score;
             $i_p_count -= 1;
         }
     }
     // We should still get all the keys, just with several empty results
     $this->assertTrue($i_skips > 0);
     $this->assertEquals(0, $i_p_score);
     $this->assertEquals(0, $i_p_count);
 }
开发者ID:remicollet,项目名称:phpredis,代码行数:63,代码来源:TestRedis.php

示例5: save

	public function save(){
		Redis::hmset("Repository::{$this->id}", 'name', json_encode($this->name), 'url', json_encode($this->url));
		
		// Can't recommend an uploaded file to a user, so don't bother inserting
		// it into the ranking sets, and go ahead and remove the reference to it
		// at some point in the near future
		if($this->isUpload()){
			Redis::expire("Repository::{$this->id}", UPLOAD_EXPIRE_TIME);
			return;
		}
		
		// If it is a repository, we want to insert it into the ranking sets	
		foreach($this->features() as $type => $attributes){
			foreach($attributes as $attribute => $value){
				Redis::zadd("Match::{$type}::{$attribute}", $value, $this->id);
			}
		}
	}
开发者ID:nickyleach,项目名称:OSS-Match,代码行数:18,代码来源:Repository.php

示例6: testZX


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

示例7: array

echo 'DB size: ' . $redis->dbSize() . PHP_EOL;
echo '___________________________' . PHP_EOL;
$p = array();
$keys = $redis->keys('*');
$d = ':';
$z = 'readmin:patterns';
foreach ($keys as $key) {
    $parts = explode($d, $key);
    $pk = '';
    foreach ($parts as $key => $part) {
        if ($key == count($parts) - 1) {
            // Добавляем строки только первого уровня
            if (count($parts) == 1) {
                $pk .= $part;
            }
        } else {
            $pk .= $part . $d . '*';
        }
        if (array_key_exists($pk, $p)) {
            $p[$pk] = $p[$pk] + 1;
        } else {
            $p[$pk] = 1;
        }
    }
}
// Добавляем шаблоны в редис
$redis->del($z);
foreach ($p as $key => $value) {
    $redis->zadd($z, $value, $key);
}
echo 'Time ago: ' . (microtime(true) - $start) . PHP_EOL;
开发者ID:xingcuntian,项目名称:readmin,代码行数:31,代码来源:create_tree.php

示例8: array

echo (int) $bool;
$bool = $redis->sMove("myset", "myset1", 35);
echo $bool;
$data = $redis->smembers("myset");
$bool = $redis->sismember("myset", 555);
echo (int) $bool;
echo $redis->scard("myset");
$redis->sinterstore("output", "myset", "myset1");
$data = $redis->smembers("output");
echo "<pre>";
// sort
$data = $redis->sort("myset", array("sort" => "desc"));
echo "<pre>";
print_r($data);
for ($i = 0; $i < 10; $i++) {
    $redis->zadd("zset", $i + rand(10, 99), $i + rand(100, 999));
}
$data = $redis->zrange("zset", 0, 3, "withscores");
echo "<pre>";
print_r($data);
$redis->zrem("zset", 456);
echo $redis->zcount("zset", 10, 50);
$redis->zRemRangeByScore("key", star, end);
echo $redis->zScore("zset", 503);
echo $redis->zrank("zset", 723);
for ($i = 0; $i < 10; $i++) {
    $redis->hset("myhash", $i, rand(10, 99) + $i);
}
echo $redis->hget("myhash", "0");
echo $redis->hlen("myhash");
echo $redis->hdel("myhash", "0");
开发者ID:isS,项目名称:NoSQL,代码行数:31,代码来源:redisWithPHP.php

示例9: Redis

<?php

include 'Redis.php';
$redis = new Redis();
$redis->debug = true;
$redis->nonempty = 'abv';
$redis->empty = '';
var_dump($redis->empty);
var_dump($redis->unset);
var_dump($redis->nonempty);
// Test binary safety using UTF8 keys and data (in bulgarian)
$redis->{'КИРИЛИЦА'} = "ДА";
var_dump($redis->{'КИРИЛИЦА'});
// Test __call
var_dump($redis->zadd("zkey", 1, "one"));
var_dump($redis->zadd("zkey", 2, "two"));
var_dump($redis->zadd("zkey", 3, "three"));
var_dump($redis->zcard("zkey"));
var_dump($redis->zrevrank("zkey", "two"));
// Pipeline test
echo "---Pipeline test\n";
$s = microtime(true);
$redis->pipeline_begin();
var_dump($redis->set("pipeline1", "val1"));
var_dump($redis->set("pipeline2", "val2"));
var_dump($redis->set("pipeline3", "val3"));
var_dump($redis->set("pipeline4", "val4"));
var_dump($redis->set("pipeline5", "val5"));
var_dump($redis->get("pipeline2"));
var_dump($redis->pipeline_responses());
echo "Time: " . (microtime(true) - $s) . "\n";
开发者ID:galvani,项目名称:php-redis,代码行数:31,代码来源:test.php


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