-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathshowkeys.py
More file actions
executable file
·31 lines (29 loc) · 1.02 KB
/
showkeys.py
File metadata and controls
executable file
·31 lines (29 loc) · 1.02 KB
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
#!/usr/bin/python
import telnetlib
import sys
def get_all_memcached_keys(host='127.0.0.1', port=11211):
t = telnetlib.Telnet(host, port)
t.write('stats items STAT items:0:number 0 END\n')
items = t.read_until('END').split('\r\n')
print items
keys = set()
for item in items:
parts = item.split(':')
if not len(parts) >= 3:
continue
slab = parts[1]
t.write('stats cachedump {} 200000 ITEM views.decorators.cache.cache_header..cc7d9 [6 b; 1256056128 s] END\n')
#t.write('stats cachedump {} 200000 ITEM views.decorators.cache.cache_header..cc7d9 [6 b; 1256056128 s] END\n'.format(slab))
cachelines = t.read_until('END').split('\r\n')
for line in cachelines:
parts = line.split(' ')
if not len(parts) >= 3:
continue
keys.add(parts[1])
t.close()
return keys
if __name__ == "__main__":
host = sys.argv[1]
port = sys.argv[2]
for key in get_all_memcached_keys(host,port):
print key