Laravel Redis保存更新点击数

暂无标签

600秒更新一次

/* Redis 点击数 */
    $redis = app('redis.connection');
    $redis_name = 'redis_blog'.$blog->id;
    if(Redis::exists($redis_name)){
        $blog_views = unserialize(Redis::get($redis_name));
        $redis->set($redis_name,serialize(array('blogid'=>$blog->id,'views'=>$blog_views['views']+1,'dateline'=>$blog_views['dateline'])));
        if(time() - $blog_views['dateline'] > 600){
            // 这里更新数据……
            Redis::del($redis_name);
        }
    }else{
        $redis->set($redis_name,serialize(array('blogid'=>$blog->id,'views'=>1,'dateline'=>time())));
}