Created
February 27, 2014 12:35
-
-
Save tsee/9249260 to your computer and use it in GitHub Desktop.
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
#!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