Tutorial

Memcached Telnet Commands Example

Published on August 3, 2022
author

Pankaj

Memcached Telnet Commands Example

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 our products

About the authors
Default avatar
Pankaj

author

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.

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!

    Become a contributor for community

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

    DigitalOcean Documentation

    Full documentation for every DigitalOcean product.

    Resources for startups and SMBs

    The Wave has everything you need to know about building a business, from raising funding to marketing your product.

    Get our newsletter

    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

    The developer cloud

    Scale up as you grow — whether you're running one virtual machine or ten thousand.

    Get started for free

    Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

    *This promotional offer applies to new accounts only.