本文共 580 字,大约阅读时间需要 1 分钟。
命令行
ZADD key score member [[score member] [score member] ...]
redis> ZADD page_rank 9 baidu.com 8 bing.com(integer) 2redis> ZRANGE page_rank 0 -1 WITHSCORES1) "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第一项是这个有序列表的键,后续的项目是排序权重,和值的交替
转载地址:http://kwaui.baihongyu.com/