Created
November 15, 2013 20:02
-
-
Save gmanley/7490680 to your computer and use it in GitHub Desktop.
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
require 'net/telnet' | |
headings = %w(id expires bytes cache_key) | |
rows = [] | |
localhost = Net::Telnet::new("Host" => "localhost", "Port" => 11211, "Timeout" => 3) | |
matches = localhost.cmd("String" => "stats items", "Match" => /^END/).scan(/STAT items:(\d+):number (\d+)/) | |
slabs = matches.inject([]) { |items, item| items << Hash[*['id','items'].zip(item).flatten]; items } | |
longest_key_len = 0 | |
slabs.each do |slab| | |
localhost.cmd("String" => "stats cachedump #{slab['id']} #{slab['items']}", "Match" => /^END/) do |c| | |
matches = c.scan(/^ITEM (.+?) \[(\d+) b; (\d+) s\]$/).each do |key_data| | |
cache_key, bytes, expires_time = key_data | |
if cache_key.starts_with?('search:') | |
Rails.cache.delete(cache_key) | |
end | |
end | |
end | |
end | |
# row_format = %Q(|%8s | %28s | %12s | %-#{longest_key_len}s |) | |
# puts row_format%headings | |
# rows.each{|row| puts row_format%row} | |
localhost.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment