Created
April 2, 2020 08:29
-
-
Save kurochan/8a833b4f470befc3fa4595e251bb64c9 to your computer and use it in GitHub Desktop.
This file contains 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 'socket' | |
MEMCACHED_PORT = 11211 | |
ip = ARGV[0] | |
sock = TCPSocket.open(ip, MEMCACHED_PORT) | |
def send_command(command, sock) | |
sock.puts command | |
sock.flush | |
lines = [] | |
line = "" | |
while line != "END" | |
line = sock.gets.chomp | |
lines << line | |
end | |
lines | |
end | |
res = send_command("stats slabs", sock) | |
slab_ids = res.map do |line| | |
m = line.match(/STAT (.*):.*/) | |
if m | |
m[1] | |
else | |
nil | |
end | |
end.select{|id| id}.uniq | |
memcached_keys = slab_ids.map do |id| | |
res = send_command("stats cachedump #{id} 0", sock) | |
res.map do |line| | |
m = line.match(/ITEM (.*) \[.*/) | |
if m | |
m[1] | |
else | |
nil | |
end | |
end.select{|id| id} | |
end.flatten | |
puts memcached_keys | |
sock.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment