redis 排序

阅读更多
/**
     * @param $key  通过 redis Sadd 存储的一个值
     * @param $sort_by   radio:list:albumList 另外一个key 键 hash键
     * @param $start
     * @param $page_size
     * @return array
     * @throws BaseException
     */
    protected  function getRedisRadioList($key,$sort_by,$start,$page_size){
        $sort = array(
            'BY' => "radio:list:albumList:*->" . $sort_by, //排序条件
            'SORT' => 'desc',
            'limit' => array($start, $page_size),//分页
            'get' => ["#",                            //id值
                "radio:list:albumList:*->radio_album_id",
                "radio:list:albumList:*->name",
                "radio:list:albumList:*->host_id",
                "radio:list:albumList:*->views",
                "radio:list:albumList:*->radio_types",
                "radio:list:albumList:*->radio_album_id",
                "radio:list:albumList:*->play_times",
                "radio:list:albumList:*->total",
                "radio:list:albumList:*->album_img",
                "radio:list:albumList:*->desc",
                "radio:list:albumList:*->single_price",
                "radio:list:albumList:*->album_price",
                "radio:list:albumList:*->published_at",
                "radio:list:albumList:*->hot_number",
                "radio:list:albumList:*->created_by",
                "radio:list:albumList:*->create_time",
                "radio:list:albumList:*->update_time",
                "radio:list:albumList:*->is_share",
                "radio:list:albumList:*->status",
                "radio:list:albumList:*->is_best",
                "radio:list:albumList:*->num",
            ]
        );

        $album_list = $this->redis->sort($key, $sort);
        $album_list = array_chunk($album_list, 22, false); //return $album_list;
        $map_key = ["radio_album_id",
            "name",
            "host_id",
            "views",
            "radio_types",
            "radio_album_id",
            "play_times",
            "total",
            "album_img",
            "desc",
            "single_price",
            "album_price",
            "published_at",
            "hot_number",
            "created_by",
            "create_time",
            "update_time",
            "is_share",
            "status",
            "is_best",
             "num"];

        $tmp_list = $album_list;
        unset($album_list);
        $item_it = [];
        if( $tmp_list ) {
            foreach ($tmp_list as $key => $item) {
                if( !empty($item['1']) ) {
                    array_shift($item);
                    for ($i = 0; $i < count($item); $i++) {
                        $k = $map_key[$i];
                        $item_it[$k] = $item[$i];
                    }
                    $album_list[] = $item_it;
                }
            }
        }

        if (0 === count($album_list)) {
            throw new \Exception\BaseException('没有更多数据');
        }

        return $album_list;
   }

你可能感兴趣的:(redis 排序)