Commit 279ac77f authored by hujun's avatar hujun

批量去除权限规则缓存

parent f84d7e73
......@@ -235,8 +235,13 @@ class RedisCacheService
$m_auth_rule = new AuthRule();
$field = 'id,name,title,pid,is_menu';
$data = $m_auth_rule->getRule($field, ['name'=>$name,'status'=>0]);
$this->setRedisCache($this->rule_key . $name, $data[0]);
$result = $data[0];
if (!empty($data)) {
$this->setRedisCache($this->rule_key . $name, $data[0]);
$result = $data[0];
} else {
$result = [];
}
} catch (\Exception $e) {
$result = [];
}
......@@ -275,7 +280,10 @@ class RedisCacheService
if (empty($result)) {
$m_auth_rule = new ASite();
$result = $m_auth_rule->getSiteList();
$this->setRedisCache($this->site_city_all_key, $result);
if (!empty($result)) {
$this->setRedisCache($this->site_city_all_key, $result);
}
} else {
$result = json_decode($result, true);
}
......@@ -294,7 +302,9 @@ class RedisCacheService
if (empty($label_data)) {
$m_label = new ULabels();
$label_data = $m_label->getColumn('id,name', ['type'=>1]); //获取标签
$this->setRedisCache($this->label_call_key, $label_data);
if (!empty($label_data)) {
$this->setRedisCache($this->label_call_key, $label_data);
}
} else {
$label_data = json_decode($label_data, true);
}
......
......@@ -766,6 +766,7 @@ Route::group('task', [
'delAgent' => ['task/UpdateRedisCache/delAgent', ['method' => 'get']],//清空经纪人缓存
'delCache' => ['task/UpdateRedisCache/delCache', ['method' => 'get']],//清空多种缓存
'delGroup' => ['task/UpdateRedisCache/delGroup', ['method' => 'get']],//批量去除角色缓存
'delRule' => ['task/UpdateRedisCache/delRule', ['method' => 'get']],//批量去除规则缓存
]);
Route::group('broker', [
......
......@@ -12,6 +12,7 @@ namespace app\task\controller;
use app\api_broker\service\RedisCacheService;
use app\model\AAgents;
use app\model\AuthGroup;
use app\model\AuthRule;
use think\Request;
class UpdateRedisCache
......@@ -63,4 +64,25 @@ class UpdateRedisCache
}
}
/**
* 批量去除权限规则缓存
*
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function delRule()
{
$m_rule = new AuthRule();
$rule_data = $m_rule->getRule('name', []);
$num = 0;
foreach ($rule_data as $v) {
$is_del = $this->redis_service->delRedisCache(4, $v['name']);
if ($is_del) {
$num++;
}
}
echo $num;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment