💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
~~~ /*Zset,没有重复的member,有排序顺序,创建更新同操作*/ $redis->zAdd('key',$score1,$member1,$scoreN,$memberN);//增,改,将一个或多个member元素及其score值加入到有序集key当中。[num | 0]注意存其他类型的key与key同名时会放弃添加 $redis->zRem('key','member1','membern');//删,移除有序集key中的一个或多个成员,不存在的成员将被忽略。[del_num | 0] $redis->zScore('key','member');//查,通过值反拿权 [num | null] $redis->zRange('key',$start,$stop);//查,通过位偏移范围(索引)拿member值,返回有序集key中指定偏移量分为的的成员,score从低到高排列 [array | null] $redis->zRevRange('key',$start,$stop);//查,通过位偏移范围(索引)拿member值,返回有序集key中指定偏移量分为的的成员,score从高到底排列 [array | null] $redis->zRangeByScore('key',$min,$max[,$config]);//查,通过scroe权范围拿member值,返回有序集key中,指定区间内的(从小到大排)成员[array | null] $redis->zRevRangeByScore('key',$max,$min[,$config]);//查,通过scroe权范围拿member值,返回有序集key中,指定区间内的(从大到小排)成员[array | null] ~~~ ~~~ $redis->zAdd('key1', 100, 'val0'); $redis->zAdd('key1', 101, 'val1'); $redis->zAdd('key1', 102, 'val2'); $redis->zAdd('key1', 103, 'val3'); $redis->zAdd('key1', 104, 'val4'); $redis->zAdd('key1', 105, 'val5'); $redis->zAdd('key1', 106, 'val6'); $redis->zAdd('key1', 107, 'val7'); $redis->zAdd('key1', 108, 'val8'); $redis->zAdd('key1', 109, 'val9'); $redis->zAdd('key1', 110, 'val10'); $redis->zAdd('key1', 111, 'val11'); $res1=$redis->zRange('key1', 0, -1); //['val0','val1',...,'val11'] $res3=$redis->zRange('key1', 0, -1, false); //['val0','val1',...,'val11'] $res2=$redis->zRange('key1', 0, -1, true); //['val0'=>100,'val1'=>101,...,'val11'=>111] $res4=$redis->zRevRange('key1', 0, -1, true); //['val11'=>111,'val10'=>110,...,'val0'=>100] $res=$redis->zRevRange('key1', 0, -1); //['val11','val10',...,'val0'] $index=2; $count=5; $res5=$redis->zRangeByScore('key1', 0, 111); //['val0','val1',...,'val11'] $res6=$redis->zRangeByScore('key1', 100, 111, ['withscores' => TRUE,'limit' => [$index, $count]]); //['val2','val1',...,'val6'] $res7=$redis->zRevRangeByScore('key1', 0, 111); //为什么返回的是空数组? $res8=$redis->zRevRangeByScore('key1', 100, 111, ['withscores' => TRUE,'limit' => [$index, $count]]); //为什么返回的是空数组? ~~~ ~~~ $redis->zRank('key','member');//查,返回有序集中指定成员的排名(索引)。其中有序集成员按分数值递增(从小到大)顺序排列[order | null] $redis->zrevrank('key','member');//查,返回有序集合中指定成员的排名(索引),有序集成员按分数值递减(从大到小)排序[order | null] $redis->zCard('key');//返回集合key的基数(集合中元素的数量)。[num | 0] $redis->zCount('key',0,-1);//返回有序集key中,score值在min和max之间(默认包括score值等于min或max)的成员数量。[num | 0] //zIncrBy(key,score,value) - 按给定的值自增score分 返回double类型的score总值 $redis->zIncrBy('key', 1, 'member1'); // 1 $redis->zIncrBy('key', 2.5, 'member1'); // 3.5 zInter(newkey,arrayZSetKeys=[k1,k2,kn], arrayWeights=[score1,score2,scoren],aggregateFunction ='SUM|MAX|MIN') //保存 k1~kn有序集合的交集 到newkey中,并返回并集新集合成员的个数 //zInter('newkey', ['k1', 'k2'], [1, 1],'SUM');//第三个参数arrayWeights的默认值每个都为1,第四个参数aggregateFunction默认为SUM //newkey元素的score计算规则 //当第四个参数为sum时:(arrayZSetKeys[0]_score*arrayWeights[0])+(arrayZSetKeys[1]_score*arrayWeights[1])+(arrayZSetKeys[n]_score*arrayWeights[n]) //当第四个参数为max时: max(arrayZSetKeys[0]_score,arrayZSetKeys[1]_score,arrayZSetKeys[n]_score)*max(arrayWeights[0],arrayWeights[1],arrayWeights[n]) //当第四个参数为min时: min(arrayZSetKeys[0]_score,arrayZSetKeys[1]_score,arrayZSetKeys[n]_score)*min(arrayWeights[0],arrayWeights[1],arrayWeights[n]) $redis->delete('k1');$redis->delete('k2');$redis->delete('k3'); $redis->delete('ko1');$redis->delete('ko2');$redis->delete('ko3');$redis->delete('ko4'); //k1=>[[0.0,val0],[1.0,val1],[3.0,val3]] $redis->zAdd('k1', 0, 'val0'); $redis->zAdd('k1', 1, 'val1'); $redis->zAdd('k1', 3, 'val3'); //k2=>[[2.0,val1],[3.0,val3]] $redis->zAdd('k2', 2, 'val1'); $redis->zAdd('k2', 3, 'val3'); $a=$redis->zInter('ko1', ['k1', 'k2']); //返回 2 此时:'ko1' => [[3.0,val1],[6.0,val3]] 1*1+2*1 3*1+3*1 $b=$redis->zInter('ko2', ['k1', 'k2'], [1, 1]); // 2, 'ko2' => [[3.0,val1],[6.0,val3]] 1*1+2*1 3*1+3*1 $b=$redis->zInter('ko5', ['k1', 'k2'], [1, 10]); // 2, 'ko5' => [[21.0,val1],[33.0,val3]] (1*1)+(2*10) (3*1)+(3*10) $b=$redis->zInter('ko6', ['k1', 'k2'], [1, 10],'SUM'); // 2, 'ko6' => [[21.0,val1],[33.0,val3]] (1*1)+(2*10) (3*1)+(3*10) $b=$redis->zInter('ko7', ['k1', 'k2'], [5, 10],'MIN'); // 2, 'ko7' => [[5.0,val1],[15.0,val3]] mim(1,2)*5 min(3,3)*5 $c=$redis->zInter('ko3', ['k1', 'k2'], [1, 5], 'min'); // 2, 'ko3' => [[1.0,val1],[3.0,val3]] min(1,2)*1 min(3,3)*1 $d=$redis->zInter('ko4', ['k1', 'k2'], [1, 5], 'max'); // 2, 'ko4' => [[10.0,val1],[15.0,val3]] max(1,2)*5 max(3,3)*5 zRangeByLex(key,min="-",max="+" [,index,count]) //返回相同score情况下指定有序集合键key的(介于min和max之间的)成员,按成员字典正序排序, 注意:分数必须相同 //min和max必须以[或者(开头[:包含(:不包含 或者min可以有-表示最小 max有+表示最大 注意 排序的是ASCII编码字符,utf8等其他字符排序不准确 //k1=>[a,b,...,g]; //zRangeByLex('key1','-','+');获取所有zset集合 //zRangeByLex('key1','[a or(a','(c');获取key1所有a-c之间的所有值包含a不包含c $redis->zRangeByLex('key','-','[c') // ['a','b','c']; $redis->zRangeByLex('key','-','(c') // ['a','b'] $redis->zRangeByLex('key','-','[c',1,2) // ['b','c'] 偏移从1开始且只返回两个 //zRemRangeByRank(key,start,end), zDeleteRangeByRank(key,start,end) - 删除所有有在索引(下标)start~end之间的有序集合返回删除的个数 $redis->zAdd('key', 1, 'one'); $redis->zAdd('key', 2, 'two'); $redis->zAdd('key', 3, 'three'); $redis->zRemRangeByRank('key', 0, 1); //2 //zRemRangeByScore(key,score1,score2), zDeleteRangeByScore(key,score1,score2) - 删除所有有在score权重排序分score1,score2之间的有序集合返回删除的个数 $redis->zAdd('key', 0, 'val0'); $redis->zAdd('key', 2, 'val2'); $redis->zAdd('key', 10, 'val10'); $redis->zRemRangeByScore('key', 0, 3); //2 zUnion(newkey,arrayZSetKeys=[k1,k2,kn], arrayWeights=[score1,score2,scoren],aggregateFunction ='SUM|MAX|MIN') // 返回并集;用法同zInter //zScan(key,iterator,key_pattern,count) - 迭代有序集合 $it = NULL; $redis->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY); while($arr_matches = $redis->zScan('zset', $it, '*pattern*')) { foreach($arr_matches as $str_mem => $f_score) { echo "Key: $str_mem, Score: $f_score\n"; } } ~~~