Last active
December 2, 2019 10:11
-
-
Save Rpsl/d6dcbba14081ebeeb8bafa91458aebfc to your computer and use it in GitHub Desktop.
php script for delete keys by pattern from redis cluster
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$hosts = [ | |
'host1:port1', | |
'host2:port2', | |
]; | |
foreach($hosts as $host){ | |
list($host, $port) = explode(':', $host); | |
echo sprintf("-- %s:%d \n", $host, $port); | |
$redis = new Redis(); | |
$redis->connect($host, $port); | |
$it = null; | |
$redis->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY); | |
$i = 0; | |
do { | |
$keys = $redis->scan($it, 'key:mask:*', 1000); | |
foreach ($keys as $key) { | |
$i++; | |
$redis->del($key); | |
// echo sprintf("%s \n", $key); | |
} | |
usleep(200); | |
} while($it > 0); | |
echo sprintf("removed %d keys \n", $i); | |
unset($redis); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment