In earlier posts, we saw how to install memcached server on Mac OS and Unix systems. After that we worked on to start memcached server at boot time as a daemon process in Mac OS. Today, we will go through some of the basic memcached telnet commands that we can use to check the health of memcached server. These commands are very helpful in debugging purpose and can be used from any operating system with telnet installed.
If you are on unix system, then using “ps -eaf | grep memcached” command you can check the port on which its running.
For example, when I run this command on my unix system, I got below output
Pankaj:~ Pankaj$ 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 Pankaj:~ Pankaj$
So memcached is running on TCP port 11111 and in verbose mode (-vv). If you want to run as daemon process use -d option in the startup command.
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
Pankaj:~ Pankaj$ 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. Pankaj:~ Pankaj$
In the next post on memcached, I will provide information about using memcached client in Java.
Hungry for more? Checkout these amazing posts: