-
Notifications
You must be signed in to change notification settings - Fork 0
Memcached
Thierry Lam edited this page Feb 2, 2022
·
3 revisions
Assuming you have memcached running in a docker container locally at port 11211, you can list the number of unique keys with
$ echo -e "stats items" | nc localhost 11211 | grep -oe ':[0-9]*:' | sort | uniq
:11:
:9:
The identification immediately on the right of items:
indicates a key. View the key name with
$ echo -e "stats cachedump 11 100" | nc localhost 11211
from pymemcache.client import base
client = base.Client(("localhost", 11211))
memcached_ids = []
for key, _ in client.stats("items").items():
_, number, _ = str(key).split(":")
if number not in memcached_ids:
memcached_ids.append(number)
memcached_keys = []
for id in memcached_ids:
memcached_keys.extend(client.stats("cachedump", id, str.encode("100")).keys())
print(memcached_keys)
for key in memcached_keys:
print(key, client.get(key.decode("utf-8")))