Tutorial

Memcached Telnet Commands Example

Published on August 3, 2022
Default avatar

By Pankaj

Memcached Telnet Commands Example

While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.

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.

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:

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

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.
$

memcached telnet commands example, memcached set, get, flush_all, stats example 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.

Learn more about us


About the authors
Default avatar
Pankaj

author

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
JournalDev
DigitalOcean Employee
DigitalOcean Employee badge
April 3, 2015

Thanks, nice tip

- Binh Thanh Nguyen

    Try DigitalOcean for free

    Click below to sign up and get $200 of credit to try our products over 60 days!

    Sign up

    Join the Tech Talk
    Success! Thank you! Please check your email for further details.

    Please complete your information!

    Get our biweekly newsletter

    Sign up for Infrastructure as a Newsletter.

    Hollie's Hub for Good

    Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

    Become a contributor

    Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

    Welcome to the developer cloud

    DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

    Learn more
    DigitalOcean Cloud Control Panel