同排名只能有一个,不能并列出现此点注意,且php zRange 时还不能指定withscores参数,网上说好像就是有此BUG存在。

Redis 类/**
* 将成员添加到有序列表中
* @param $key
* @param $node  对应的需要填入的值(比如学生的id)
* @param int $nums 对应的分数,默认值为1
* @return mixed
*/
public function zadd($key,$node,$nums = 1){
self::init();
$key = self::makekey($key);
return self::$redis->zAdd($key,$nums,$node);
}
/**
* 获取对应的排行榜
* @param $key
* @param $number 需要给出排行榜数目
* @param bool $asc $asc 排序顺序 true为降序(按照高分为第0)
* @param bool $withscores 是否需要分数
* @param null $callback 用于处理排行榜的回调函数
* @return mixed
*/
public function zRevRange($key, $number, $asc = true, $withscores = false, $callback = null)
{
self::init();
$key = self::makekey($key);
if ($asc) {
$List = self::$redis->zRevRange($key, 0, $number - 1); //降序
} else {
$List = self::$redis->zRange($key, 0, $number - 1);//升序
}
if ($callback) {
return call_user_func_array($callback, $List);
}
return $List;
}
/**
* @param $key
* @param $node
* @param bool $asc
* @return mixed
*/
public function getNodeRange($key, $node, $asc = true)
{
self::init();
$key = self::makekey($key);
if ($asc) {
//zRevRank 分数最高的排行为0,所以需要加1位
return self::$redis->zRevRank($key, $node);
} else {
return self::$redis->zRank($key, $node);
}
}
实现类public function testStudentsTopAction(){
$cache = new Cache_Redis();
$this->db = Db_Connection::factory('yr');
$key = "student_top";
$sql = "select * from wjy_school_branch_student where status = 1 GROUP BY total_star order by total_star DESC limit 1000 ";
$arrList = $this->db->fetchAll($sql,array());
foreach($arrList as $one){
//入有序列表
$res = $cache->zadd($key,$one['id'],$one['total_star']);
}
}
public function getTestStudentsTopAction(){
$cache = new Cache_Redis();
$key = "student_top";
$res = $cache->zRevRange($key,100,true,true);
//        $res = $cache->getNodeRange($key,106039,true);
dump($res);
}