1、存redis

使用setex命令可以同时设置数据和保存时间
$data = [
    'name'=>zhangsan,
    'age' => 28,
    'sex' => 1
];

Redis::setex($cacheKey, 300, serialize($data));

 

2、取redis

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

 

3、更新redis

修改或者删除以后

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

 

相关文章:

  • 2021-08-14
  • 2021-10-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-26
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-28
  • 2022-12-23
  • 2021-10-03
  • 2022-01-02
相关资源
相似解决方案