redid 分页 查询 批量删除

redis = Redis::connection('online');

       $this->totalCount=$this->redis->lLen(config('param.REDIS_KEY'));

       // $this->db = DBUtil::urlqueneConnect();
    }
    /**
     * 类型List 键值:queue:urls
     * @param  Request $request [description]
     * @return [type]           [description]
     */
    public function index(Request $request)
    {
        $size = empty($request->size)?10:$request->size;

        $maxSize = empty($request->maxSize)?10:$request->maxSize;

        $this->currentPage = empty($request->page)?1:$request->page;

        $this->pageSize=$size;
        $this->maxSize=$maxSize;

        $this->pageNum=ceil($this->totalCount/$this->pageSize);

        $redis_urls = $this->pageCaclt($this->currentPage);
        $page_html = $this->gainLi($this->currentPage);

        $data['page_html'] = $page_html;

        $data['redis_url'] = $redis_urls;

        return view('admin.warnsave.urllist',$data);
    }

    public function pageCaclt($page){

        if($page<1||$page > $this->pageNum)
        {
            $page=1;
        }

        $start=($page-1)*$this->pageSize;

        $data = $this->redis->lRange(config('param.REDIS_KEY'),$start,($start+$this->pageSize-1));

        return $data;
    }

    public function gainLi($page){
        if($page<1||$page>$this->pageNum)
        {
            $page=1;
        }

        $pageLi="";
        if($this->pageNum<=$this->maxSize){
            $pageLi.="
共{$this->pageNum}页 "; for($i=1;$i<$this->pageNum;$i++){ if($i==$page) $pageLi.="$i   "; else $pageLi.="$i   "; } $pageLi.="
"; } else{ $pre=$page>1?$page-1:1; $next=$page<$this->pageNum?$page+1:$this->pageNum; $divide=($this->maxSize-1)/2; $left=$page-$divide; if($left<1) $left=1; if($left+$this->maxSize>=$this->pageNum) $left=$this->pageNum-$this->maxSize+1; $right=$left+$this->maxSize-1; $pageLi.="
共{$this->pageNum}页 "; if($page==1){ $pageLi.="首页  "; $pageLi.="上一页  "; } else{ $pageLi.="首页  "; $pageLi.="上一页  "; } for($i=$left;$i<=$right;$i++){ if($i==$page) $pageLi.="$i  "; else $pageLi.="$i  "; } if($page==$this->pageNum){ $pageLi.="下一页  "; $pageLi.="尾页"; } else{ $pageLi.="下一页  "; $pageLi.="尾页"; } $pageLi.="
"; } return $pageLi; } public function create(Request $request) { return view('admin.warnsave.urlcreate'); } public function store(Request $request) { $url = empty($request->url)?'':$request->url; if(empty($url))return redirect()->back()->withErrors(['错误','msg'=>'该URL 不能为空,请输入']); if(!HttpUtil::isCheckUrl($url))return redirect()->back()->withErrors(['错误','msg'=>'该URL 无效,请重新输入']); $this->redis->lpush(config('param.REDIS_KEY'),$url); return redirect('/manage/wsurl'); } public function redisDel(Request $request) { $url = $request->url; $this->redis->lrem(config('param.REDIS_KEY'),0,$url); return redirect('/manage/wsurl'); } /** * 批量删除 * @param Request $request [description] * @return [type] [description] */ public function redisDelAll(Request $request) { $ids = empty($request->ids)?'':$request->ids; if(empty($ids))exit(json_encode(['status'=>false,'msg'=>'请选择要删除的URL'])); $ids_tmp = explode(',', $ids); foreach ($ids_tmp as $key => $value) { $this->redis->lrem(config('param.REDIS_KEY'),0,$value); } exit(json_encode(['status'=>true,'msg'=>'删除成功'])); } }

你可能感兴趣的:(php框架,laravel,redis)