How to view memcached data

How to view memcached data.

Connect to memcached with telnet

$ telnet 11211
Connected to localhost.
Escape character is '^]'.

Get value by key

get 067c92d96d0f84e3627f255198ad79b8a15fb66a03a2fc45e8ee94e247ae
VALUE 067c92d96d0f84e3627f255198ad79b8a15fb66a03a2fc45e8ee94e247ae 0 143

Get stats items to find out the slab id

stats items
STAT items:6:number 4
STAT items:6:number_hot 0
STAT items:8:number 1
STAT items:8:number_hot 0

where the number (e.g. 6 or 8 above) after items is the slab id.

Get keys under a slab with cachedump command

for Memcached 1.4.30 and below

stats cachedump 6 0
ITEM 805f42ea4ebfa1e317544497eb11986b132394ea8994401848a970ac1316 [143 b; 1689326480 s]
ITEM a25f1fa74c8ac3896bed858f8b13c56346322ff5d850a36fe38aeb451587 [143 b; 1689326480 s]
ITEM 6cbdb651657605afdf9f7d8610922695f0df5d48c103895f826d8072d65a [143 b; 1689326480 s]

where 6 is the slab id and 0 is the number of keys to dump and 0 means all.

Get all keys with lru_crawler metadump all

for Memcached 1.4.31 and above

lru_crawler metadump all
key=888330c7b5d106a351803a4f917e72032bf7efa559ac54454ec50d8ba0f9 exp=1689326480 la=1689297902 cas=12 fetch=yes cls=6 size=262

See How do I view the data in memcache? and get all keys set in memcached