Difference between revisions of "Memcached List all Keys"
From Brian Nelson Ramblings
(Created page with "==Memcached List all Keys== In the general case, there is no way to list all the keys that a memcached instance is storing. You can, however, list something like the first 1M...") |
(No difference)
|
Latest revision as of 14:43, 22 August 2015
Contents
Memcached List all Keys
In the general case, there is no way to list all the keys that a memcached instance is storing. You can, however, list something like the first 1Meg of keys, which is usually enough during development.
Connect to your Memcached Instance
We have multiple ways to set up memcache instances (tcp or socket)
Connect to Memcached TCP Instance
telnet 127.0.0.1 11211
Connect to Memcached Socket Instance
nc -U /path/to/socket
Now we need to get the slab ids
List the items to get the slab id:
stats items
STAT items:5:number 2 STAT items:5:age 1390736 STAT items:5:evicted 0 STAT items:5:evicted_nonzero 0 STAT items:5:evicted_time 0 STAT items:5:outofmemory 0 STAT items:5:tailrepairs 0 STAT items:6:number 260 STAT items:6:age 1385409 STAT items:6:evicted 0 STAT items:6:evicted_nonzero 0 STAT items:6:evicted_time 0 STAT items:6:outofmemory 0 STAT items:6:tailrepairs 0
The first number after ‘items’ is the slab id. Request a cache dump for each slab id, with a limit for the max number of keys to dump:
stats cachedump 3 100 ITEM views.briansnelson.cache.cache_header..cc7d9 [6 b; 1256056128 s] END
stats cachedump 22 100 ITEM views.briansnelson.cache.cache_page..8427e [7736 b; 1256056128 s] END
Now you should be able to list and view the keys