larval 使用redis作缓存

一、存redisphp

使用setex命令能够同时设置数据和保存时间
复制代码
$data = [
    'name'=>zhangsan,
    'age' => 28,
    'sex' => 1
];

Redis::setex($cacheKey, 300, serialize($data));
复制代码

 

二、取redisredis

 if (Redis::exists($cacheKey) {
            $res = Redis::get($cacheKey);
            $res = unserialize($res);
        } else{
    //从数据库读取数据
}    

 

三、更新redis数据库

修改或者删除之后spa

 if(Redis::exists($cahceKey){
                Redis::del($cahceKey);
            }

 

 

我的公众号谢谢各位老铁支持
code

相关文章
相关标签/搜索