赞
踩
命令行
ZADD key score member [[score member] [score member] ...]
redis> ZADD page_rank 9 baidu.com 8 bing.com
(integer) 2
redis> ZRANGE page_rank 0 -1 WITHSCORES
1) "bing.com"
2) "8"
3) "baidu.com"
4) "9"
5) "google.com"
6) "10"
使用phpredis
// call_user_func_array(array($this->redis, 'zadd'), array('key', 0, 'we', 2, 'me', 3, 'td', 8, 'go'));
$set = [$cachekey];
foreach($data as $member => $score){
array_push($set, $score, $member);
}
call_user_func_array(array($this->redis, 'zadd'), $set);
或者静态调用
call_user_func_array([Redis::class, 'zadd'], $set);
//array第一项是这个有序列表的键,后续的项目是排序权重,和值的交替
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。