有时候忘记给redis的key设置过期时间
而redis的使用规则是尽量给key设置过期时间
有没有办法批量设置过期时间?以下是代码
<?php
namespace app\index\controller;
use think\Db;
use think\facade\Cookie;
use think\facade\Config;
use think\facade\Cache;//需要配置cache.php
use app\common\model\Base;
class Test extends Base
{
public function a1(){
$list = Cache::store('redis')->rawCommand('keys',"*zj*");
echo "<pre>";
//print_r($list);
foreach($list as $k=>$v){
echo $v."<>";
//echo Cache::store('redis')->rawCommand('get',$v);
//设置当天过期
Cache::store('redis')->rawCommand("expire",$v,strtotime(date('Y-m-d').'23:59:59') - time());
echo "<br>";
}
}
}
如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术
转载请注明:thinkphp5批量设置redis的key过期时间 出自老鄢博客 | 欢迎分享