Hello everyone!

We have been investing plenty of personal time and energy for many years to share our knowledge with you all. However, we now need your help to keep this blog running. All you have to do is just click one of the adverts on the site, otherwise it will sadly be taken down due to hosting etc. costs. Thank you.

This tutorial shows us how to install and interact with memcached server in terminal. For more info, check cheat sheet and use phpMemcachedAdmin browser GUI.

Install Memcached

sudo apt-get install php5 php5-dev php5-memcached memcached
sudo apt-get install memdump

Verify installation

echo "stats settings" | nc localhost 11211

Check what IP and port memcached is running

ps -ef

Live run-time stats

watch "echo stats | nc 11211"


telnet 11211

List all items

Use stats items to list all items and dump details of given item with stats cachedump 3 100.

telnet 11211

stats items
STAT items:3:number 1
STAT items:3:age 498
STAT items:22:number 1
STAT items:22:age 498

# 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.decorators.cache.cache_header..cc7d9 [6 b; 1256056128 s]

stats cachedump 22 100
ITEM views.decorators.cache.cache_page..8427e [7736 b; 1256056128 s]

Setting and getting keys

set my_key_name 0 86400 7 # Set with a "flag" of 0, a TTL of 86400 seconds and 7 bytes of data
inanzzz # Value to set is entered on a separate line. Length matches the number 7 above

get my_key_name # Get the key "my_key_name" from memcached and return "inanzzz"