Skip to content

Instantly share code, notes, and snippets.

@Rpsl
Last active December 2, 2019 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rpsl/d6dcbba14081ebeeb8bafa91458aebfc to your computer and use it in GitHub Desktop.
Save Rpsl/d6dcbba14081ebeeb8bafa91458aebfc to your computer and use it in GitHub Desktop.
php script for delete keys by pattern from redis cluster
<?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