Skip to content

Instantly share code, notes, and snippets.

@sokil
Last active March 28, 2022 07:43
Show Gist options
  • Select an option

  • Save sokil/92a9fc09e8f6a5ffe9691bb0dcaa97b4 to your computer and use it in GitHub Desktop.

Select an option

Save sokil/92a9fc09e8f6a5ffe9691bb0dcaa97b4 to your computer and use it in GitHub Desktop.
telnet memcached

Connect to memcached

telnet localhost 11211

Get slabs info

stats slabs
stats items

Find key in cache

# stats cachedump <slab class> <number of items to dump>
for i in {1..35}; do 
    (sleep 1; echo "stats cachedump $i 0"; sleep 1; echo "quit";) | telnet localhost 11211 | grep SOME_KEY ; 
done
ITEM 97777791f0776e9bf5095cb5c4b54b2a [27 b; 1517406013 s] 
ITEM <item_key> [<item_size> b; <expiration_timestamp> s]

Get value

(sleep 0.1; echo "get 97777791f0776e9bf5095cb5c4b54b2a"; sleep 0.1; echo "quit";) | telnet localhost 11211;
VALUE 97777791f0776e9bf5095cb5c4b54b2a 0 27
a:2:{i:0;i:38681844;i:1;N;}
END

Get all geys with stats:

lru_crawler metadump all

Memcache removes expired key only after trying to get it

(sleep 0.1; echo "stats cachedump 3 0"; sleep 0.1; echo "quit";) | telnet localhost 11211 | grep 97777791f0776e9bf5095cb5c4b54b2a
ITEM 97777791f0776e9bf5095cb5c4b54b2a [27 b; 1517408089 s]
Connection closed by foreign host.
(sleep 0.1; echo "stats cachedump 3 0"; sleep 0.1; echo "quit";) | telnet localhost 11211 | grep 97777791f0776e9bf5095cb5c4b54b2a
ITEM 97777791f0776e9bf5095cb5c4b54b2a [27 b; 1517408089 s]
Connection closed by foreign host.
(sleep 0.1; echo "get 97777791f0776e9bf5095cb5c4b54b2a"; sleep 0.1; echo "quit";) | telnet localhost 11211;
END
Connection closed by foreign host.
(sleep 0.1; echo "stats cachedump 3 0"; sleep 0.1; echo "quit";) | telnet localhost 11211 | grep 97777791f0776e9bf5095cb5c4b54b2a
Connection closed by foreign host.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment