Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Memcache contents
require 'rubygems'
require 'net/telnet'
require 'memcache'
require 'action_view'
include ActionView::Helpers::TextHelper
cache = 'localhost:11211'
raw ="Host" => "localhost", "Port" => 11211, "Prompt" => /END/)
items = raw.cmd("stats items")
keys = items.split(/\n/).
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment