Created
April 4, 2013 09:51
-
-
Save geoffgarside/5309183 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
#!/usr/bin/env ruby | |
require 'net/telnet' | |
prefix = ARGV.length > 1 ? ARGV[1] : nil | |
prefix_regexp = prefix && Regexp.new("\A#{prefix}") | |
cache_dump_limit = 100 | |
localhost = Net::Telnet::new("Host" => "localhost", "Port" => 11211, "Timeout" => 3) | |
slab_ids = [] | |
localhost.cmd("String" => "stats items", "Match" => /^END/) do |c| | |
matches = c.scan(/STAT items:(\d+):/) | |
slab_ids = matches.flatten.uniq | |
end | |
cache_keys = [] | |
slab_ids.each do |slab_id| | |
localhost.cmd("String" => "stats cachedump #{slab_id} #{cache_dump_limit}", "Match" => /^END/) do |c| | |
matches = c.scan(/^ITEM (.+?) \[(\d+) b; (\d+) s\]$/).each do |key_data| | |
(cache_key, _, _) = key_data | |
if cache_key =~ /\:session\:/i | |
next | |
elsif prefix_regexp && prefix_regexp.match(cache_key) | |
cache_keys << cache_key | |
else | |
cache_keys << cache_key | |
end | |
end | |
end | |
end | |
localhost.close | |
cache_keys.sort.each do |key| | |
puts key | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment