Skip to content

Instantly share code, notes, and snippets.

@stackdump
Forked from bkimble/gist:1365005
Created December 14, 2011 23:07

Revisions

  1. @bkimble bkimble created this gist Nov 14, 2011.
    27 changes: 27 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    #!/usr/bin/env ruby
    require 'net/telnet'

    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


    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