Skip to content

Instantly share code, notes, and snippets.

@kurochan
Created April 2, 2020 08:29
Show Gist options
  • Save kurochan/8a833b4f470befc3fa4595e251bb64c9 to your computer and use it in GitHub Desktop.
Save kurochan/8a833b4f470befc3fa4595e251bb64c9 to your computer and use it in GitHub Desktop.
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