当前位置:网站首页>Redis implements paging

Redis implements paging

2022-06-09 16:21:00 Fox catsup

redis Implement paging

  1. Use in order zadd

  2. Use hash Store specific data

  3. Get data through an ordered set of ZREVRANGE— Descending sort

Code case

// Sort in descending chronological order 
// Save the data 
$redis->zAdd($key,$article['add_time'],'article:'.$artice['id']);
$redis->hMset('article'.$article['id'],$article);

// Take the data 
 $result = $redis->zRevRange($key,$start,$start+10,true);  // Get data , every time 10 Data 
 $count = $redis->ZCARD($key);  // Get the total number 

foreach($result as $k=>$v){
      $article = $reids->hGetAll($k)  // Specific data of each article 
}

原网站

版权声明
本文为[Fox catsup]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206091554239165.html