Incr
$views = Redis::incr(‘views‘); $article_views = Redis::incr(‘article:‘ . $article_id . ‘:views‘);
zIncrBy 有序集合 增加
public function set($id) { Redis::zIncrBy(‘articleViews‘, 1, ‘article:‘.$id); } public function get() { $hots = Redis::zRevRange(‘articleViews‘, 0, -1); foreach($hots as $index => $hot){ $id = str_replace(‘article:‘, ‘‘, $hot); $views = Redis::zScore(‘articleViews‘, $hot); echo $index+1 . ‘)‘. ‘the article id is ‘.$id.‘, it has ‘.$views.‘ views<br>‘; } }
Cache 缓存
public function show() { return Cache::remember(‘post_cache‘, 1, function () { return Post::first(); }); }
时间: 2024-10-23 10:51:30