public
Created

memcache checker

  • Download Gist
memcache_checker.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#!/usr/bin/python
# memcache_checker.py
#
# checks a list of memcache servers for a given key
# usage: memcache_checker.py <key>
 
import sys
import socket
 
# a list of (host, port) tuples
 
servers = (
# YOUR SERVERS HERE
# ('127.0.0.1', 11211),
)
 
def netcat(hostname, port, content):
# from http://stackoverflow.com/questions/1908878/netcat-implementation-in-python/1909355#1909355
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((hostname, port))
s.sendall(content)
s.shutdown(socket.SHUT_WR)
while 1:
data = s.recv(1024)
if data == "":
break
return data
s.close()
 
for server in servers:
command = "get %s\nquit"%sys.argv[1]
print "server %s:"%(server,)
print netcat(server[0], server[1], command)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.