Skip to content

Instantly share code, notes, and snippets.

@eabbott
Forked from bkimble/gist:1365005
Last active December 13, 2015 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eabbott/4957893 to your computer and use it in GitHub Desktop.
Save eabbott/4957893 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'net/telnet'
hostname = ARGV[0]
throw 'wheres the host?' if hostname.nil?
cache_dump_limit = 10000
localhost = Net::Telnet::new("Host" => hostname, "Port" => 11211, "Timeout" => 3, "Telnetmode" => false)
slab_ids = []
# The code block will get called for each <insert technical expl>
localhost.cmd("String" => "stats items", "Match" => /^END/) do |c|
slab_ids = slab_ids + c.scan(/STAT items:(\d+):/).flatten.uniq
end
slab_ids = slab_ids.flatten.uniq
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
puts "[#{humanized_expires_time}]\t#{cache_key}"
end
end
end
puts
localhost.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment