- 在redis中我们使用有序集合一般是利用score进行数据的筛选,一般score存放时间戳,用来进行时间段筛选
- 问题:利用
ZRANGEBYSCORE key min max
进行筛选在数据量非常大的情况下,全部查询出来,放到页面渲染导致页面非常的慢,需要进行分页处理 ZCARD key
获取有序集合的成员数,ZRANGE key start stop [WITHSCORES]
通过索引进行查询的方式,如不通过时间去筛选,直接用索引进行分页是最好的,功能中需要时间筛选,这里只能对查询出来的数据进行手动切割分页- 将redis数据通过时间区间全部查询出来,再用数组进行分块,根据输入的页码进行取块
private function pageData($data,$page=null){
$count = count($data);
$limit = 16;
$total = ceil($count/16);
$chunks = array_chunk($data,16);
if ($page){
$cur_page = $page;
$pre = $cur_page-1;
$next =$cur_page+1;
if ($page<1){
$cur_page =1;
$pre = $cur_page;
$next = $cur_page+1;
}
if ($page>=$total){
$cur_page = $total;
$pre = $cur_page - 1;
$next = $cur_page;
}
$hwid_datas = $chunks[$cur_page-1];
$data = ['count'=>$count,'total'=>$total,'cur_page'=>$cur_page,'hwid_datas'=>$hwid_datas,'pre'=>$pre,'next'=>$next];
}else{
$data = ['count'=>$count,'total'=>$total,'cur_page'=>1,'hwid_datas'=>$chunks[0],'pre'=>1,'next'=>2];
}
return $data;
}
<ul class="pagination pagination-sm no-margins pull-left no-padding " style="display: inline">
第{{$data['cur_page']}}页 共{{$data['total']}} 页 共 {{$data['count']}} 条记录
</ul>
<ul class="pagination pagination-sm no-margins pull-right no-padding " style="display: inline-block">
<ul class="pagination">
<li><a href="{{route('hwtc.can.show',$id.'?d1='.$d1.'&d2='.$d2.'&page='.$data['pre'])}}">«</a></li>
<li><a href="{{route('hwtc.can.show',$id.'?d1='.$d1.'&d2='.$d2.'&page='.$data['next'])}}" rel="next">»</a></li>
</ul>
</ul>

- 基本完成上一页下一页的功能,再加一个跳转具体页码就oK了