-
-
Save volkan/2652600 to your computer and use it in GitHub Desktop.
List local memcached keys and values using Ruby
This file contains hidden or 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' | |
#ruby file.rb | |
#ruby file.rb key1, key2, key3 | |
cache_dump_limit = 100000 | |
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 | |
puts | |
puts "Expires At\t\t\t\tCache Key" | |
puts '-'* 80 | |
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, bytes, expires_time) = key_data | |
humanized_expires_time = Time.at(expires_time.to_i).to_s | |
if bytes.to_i>1048576 | |
puts "Warning!!! Look at bytes" | |
end | |
puts "[#{humanized_expires_time}]\t#{cache_key} #{bytes}" | |
end | |
end | |
end | |
puts | |
puts | |
ARGV.each do|a| | |
puts "key: #{a}" | |
localhost.cmd("String" => "get #{a}", "Match" => /^END/) do |value| | |
puts "values:" | |
puts "#{value}" | |
end | |
end | |
puts | |
localhost.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment