redis scan删除key的方法封装

public function delByScan(array $matchGroup = [])
{
if (empty($matchGroup)) return true;
$redis = RedisUtil::instance(['prefix' => '']);
$it = null;
$count = 1000;
do {
echo "scan start\n";
$arr_keys = $redis->scan($it, null, $count);
if (is_array($arr_keys) && count($arr_keys) > 0){
foreach ($arr_keys as $key){
foreach ($matchGroup as $match){
if (strpos($key, $match) !== false){
$redis->del($key);
echo "delete key => {$key} done\n";
}
}
}
}
echo "scan restart\n";
} while ($it > 0);

    return true;
}

猜你喜欢

转载自www.cnblogs.com/ryanlamp/p/10193881.html