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. 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.
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:
get KEY
To overwrite the existing key:
replace KEY META_DATA EXPIRY_TIME LENGTH_IN_BYTES
To delete the key:
delete KEY
To get the server statistics:
stats
stats items
stats slabs
To clear the cache data:
flush_all
To quit the telnet session:
quit
$ 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
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
Java and Python Developer for 20+ years, Open Source Enthusiast, Founder of https://www.askpython.com/, https://www.linuxfordevices.com/, and JournalDev.com (acquired by DigitalOcean). Passionate about writing technical articles and sharing knowledge with others. Love Java, Python, Unix and related technologies. Follow my X @PankajWebDev
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.