In this tutorial, we will go through some of the basic Memcached telnet commands that we can use to check the health of the Memcached server. These commands are very helpful in debugging purposes and can be used from any operating system with telnet installed.
If you are on a UNIX system, then using
ps -eaf | grep memcached command will get you the port Memcached server is running on.
For example, when I run this command on my UNIX system, I got below output:
$ ps -eaf | grep memcached 503 55442 55296 0 0:00.15 ttys000 0:00.22 memcached -p 11111 -vv 503 58945 56875 0 0:00.01 ttys003 0:00.01 grep memcached $
So Memcached server is running on TCP port 11111 and in verbose mode (-vv). If you want to run as daemon process then use -d option in the startup command.
Memcached Telnet Commands
To connect to memcached server with telnet and start a session:
$ telnet localhost 11111
To store data in Memcached server with telnet:
set KEY META_DATA EXPIRY_TIME LENGTH_IN_BYTES
To retrieve data from Memcached through telnet:
To overwrite the existing key:
replace KEY META_DATA EXPIRY_TIME LENGTH_IN_BYTES
To delete the key:
To get the server statistics:
stats stats items stats slabs
To clear the cache data:
To quit the telnet session:
Memcached Server Telnet Example
$ telnet localhost 11111 Trying ::1... Connected to localhost. Escape character is '^]'. set Test 0 100 10 JournalDev STORED get Test VALUE Test 0 10 JournalDev END replace Test 0 100 4 Temp STORED get Test VALUE Test 0 4 Temp END stats items STAT items:1:number 1 STAT items:1:age 19 STAT items:1:evicted 0 STAT items:1:evicted_time 0 STAT items:1:outofmemory 0 STAT items:1:tailrepairs 0 END flush_all OK get Test END version VERSION 1.2.8 quit Connection closed by foreign host. $
In the next post on memcached, I will provide information about using memcached client in Java.
Reference: Memcached Github Commands Page