发布于 2016-10-18 14:11:13 | 150 次阅读 | 评论: 0 | 来源: 网络整理

zscan

说明

列出 zset 中处于区间 (key_start+score_start, score_end] 的 key-score 列表. 如果 key_start 为空, 那么对应权重值大于或者等于 score_start 的 key 将被返回. 如果 key_start 不为空, 那么对应权重值大于 score_start 的 key, 或者大于 key_start 且对应权重值等于 score_start 的 key 将被返回.

也就是说, 返回的 key 在 (key.score == score_start && key > key_start || key.score > score_start), 并且 key.score <= score_end 区间. 先判断 score_start, score_end, 然后判断 key_start.

("", ""] 表示整个区间.

参数

name - zset 的名字.
key_start - score_start 对应的 key.
score_start - 返回 key 的最小权重值(可能不包含, 依赖 key_start), 空字符串表示 -inf.
score_end - 返回 key 的最大权重值(包含), 空字符串表示 +inf.
limit - 最多返回这么多个元素.

返回值

如果出错则返回 false, 否则返回包含 key-score 的关联数组.

示例

$ssdb->zscan('z', '', 1, 100, 10);

遍历 zset:

$key_start = ''; 
$score_start = ''; 
while(1){
    $items = $ssdb->zscan($zname, $key_start, $score_start, '', 10);
    if(!$items){
        break;
    }   
    foreach($items as $key=>$score){
        // process($key, $score)...

        // 记住最大的元素和它的权重
        $key_start = $key;
        $score_start = $score;
    }   
}
最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务