public
Last active — forked from bryanl/gist:547726

Memcache contents

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
require 'rubygems'
require 'net/telnet'
require 'memcache'
require 'action_view'
 
include ActionView::Helpers::TextHelper
 
cache = MemCache.new 'localhost:11211'
 
raw = Net::Telnet.new("Host" => "localhost", "Port" => 11211, "Prompt" => /END/)
items = raw.cmd("stats items")
keys = items.split(/\n/).
grep(/items:\w+:number/).
map{|x| x.match(/items:(\w+):number/)[1]}.
map{|x| raw.cmd("stats cachedump #{x} 100")}.
map{|x| x.split(/\s+/)[1]}
max_key_length = 0
keys.each{|key| max_key_length = key.size if key.size > max_key_length }
keys.each do |key|
data = truncate(cache.get(key).to_s.gsub(/\r\n/,'\r\n'), :length => 50)
printf("%30s | %s\n", key, data)
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.