Skip to content

Instantly share code, notes, and snippets.

@tsee
Created February 27, 2014 12:35
Show Gist options
  • Save tsee/9249260 to your computer and use it in GitHub Desktop.
Save tsee/9249260 to your computer and use it in GitHub Desktop.
#!perl
use 5.14.2;
use Redis;
use Data::Dumper;
use Time::HiRes qw(time);
my $r = Redis->new(server => 'localhost:6379');
my $total_count = $r->dbsize;
say "Total number of keys before starting: $total_count";
$|=1;
my $count = 5000;
my $cursor = 0;
my $keys;
my $start_time = time();
my $keys_scanned = 0;
while (1) {
($cursor, $keys) = $r->scan($cursor, count => $count);
$keys_scanned += @$keys;
say $keys_scanned;
if (@$keys) {
foreach my $key (@$keys) {
$r->hget(
$key, "time", sub {
#$r->delete($k, sub {}) if $expire_time < time();
}
);
}
}
last if $cursor == 0;
}
my $end_time = time();
say "Took a total of " . ($end_time-$start_time) . "s at a rate of "
. ($total_count/($end_time-$start_time)) . " keys/s.";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment