自己写的代码,删除1千万线上redis数据
$iterator = null;
$count = 1000;
$prefix = 'log:';
$this->redis->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY);
while($keys = $this->redis->scan($iterator,$prefix."*",$count)) {
foreach($keys as $key) {
if(strpos($key,'log') !== false){
$this->redis->del($key);
echo $key.PHP_EOL;
}
}
}
SCAN
SCAN cursor [MATCH pattern] [COUNT count]
- 作用:迭代当前数据库中的数据库键
- SCAN 使用 demo
<?php $redis = new Redis(); $redis->connect('127.0.0.1', 6379); /* Options for the SCAN family of commands, indicating whether to abstract empty results from the user. If set to SCAN_NORETRY (the default), phpredis will just issue one SCAN command at a time, sometimes returning an e