初始化
缺陷:主题配色需要优化整体的同风格
This commit is contained in:
@@ -91,4 +91,29 @@ class RedisService
|
||||
{
|
||||
return $this->redis::del($this->prefix . $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空当前前缀下的全部键
|
||||
*
|
||||
* 菜单这类按角色分片缓存的数据,改了菜单树要一次性失效所有角色的副本。
|
||||
* KEYS 的返回值带着 redis 客户端自身的 prefix,直接回传给 del 会二次拼前缀,所以要先剥掉。
|
||||
* @return int 删除的键数量
|
||||
*/
|
||||
public function delAll(): int
|
||||
{
|
||||
$keys = $this->redis::keys($this->prefix . '*');
|
||||
if (empty($keys)) {
|
||||
return 0;
|
||||
}
|
||||
$clientPrefix = (string) config('database.redis.options.prefix');
|
||||
$count = 0;
|
||||
foreach ($keys as $key) {
|
||||
if ($clientPrefix !== '' && str_starts_with($key, $clientPrefix)) {
|
||||
$key = substr($key, strlen($clientPrefix));
|
||||
}
|
||||
$this->redis::del($key);
|
||||
$count++;
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user