Skip to content

Instantly share code, notes, and snippets.

Last active Dec 2, 2019
What would you like to do?
php script for delete keys by pattern from redis cluster
$hosts = [
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) {
// echo sprintf("%s \n", $key);
} while($it > 0);
echo sprintf("removed %d keys \n", $i);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment