summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorJunji Hashimoto <junji.hashimoto@gmail.com>2022-03-01 10:39:58 +0900
committerdormando <dormando@rydia.net>2022-07-03 17:38:25 -0700
commite35bdee404a41fb7645a56e95e0ddb83c9f4bef7 (patch)
tree59a43935727bea26e15de70aa58e3ddcaf5129cd /scripts
parent8d356ae1523f4fec72ade529cf74ef5ddc15e4aa (diff)
downloadmemcached-e35bdee404a41fb7645a56e95e0ddb83c9f4bef7.tar.gz
Add a command to dump keys for memcached-tool
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/memcached-tool26
1 files changed, 26 insertions, 0 deletions
diff --git a/scripts/memcached-tool b/scripts/memcached-tool
index e5c1c87..34436b5 100755
--- a/scripts/memcached-tool
+++ b/scripts/memcached-tool
@@ -36,6 +36,12 @@ if ($mode eq "display") {
undef $mode if $limit < 1;
print STDERR "ERROR: invalid limit (should be a positive number)\n\n" unless $mode;
}
+} elsif ($mode eq 'keys') {
+ if (@ARGV) {
+ $limit = shift;
+ undef $mode if $limit < 1;
+ print STDERR "ERROR: invalid limit (should be a positive number)\n\n" unless $mode;
+ }
} elsif ($mode eq 'stats') {
;
} elsif ($mode eq 'settings') {
@@ -56,6 +62,7 @@ die
memcached-tool 10.0.0.5:11211 settings # shows settings stats
memcached-tool 10.0.0.5:11211 sizes # shows sizes stats
memcached-tool 10.0.0.5:11211 dump [limit] # dumps keys and values
+ memcached-tool 10.0.0.5:11211 keys [limit] # dumps keys
WARNING! sizes is a development command.
As of 1.4 it is still the only command which will lock your memcached instance for some time.
@@ -138,6 +145,25 @@ if ($mode eq 'dump') {
exit;
}
+if ($mode eq 'keys') {
+ print STDERR "Dumping memcache keys";
+ print STDERR " (limiting to $limit keys)" unless !$limit;
+ print STDERR "\n";
+ print $sock "lru_crawler metadump all\r\n";
+ my %keyexp;
+ my $keycount = 0;
+ while (<$sock>) {
+ last if /^END/ or ($limit and $keycount == $limit);
+ # return format looks like this
+ # key=foo exp=2147483647 la=1521046038 cas=717111 fetch=no cls=13 size=1232
+ if (/^key=(\S+) exp=(-?\d+) .*/) {
+ print $_
+ }
+ $keycount++;
+ }
+ exit;
+}
+
if ($mode eq 'stats') {
my %items;