How to Test Memcached Connectivity

If you’re looking to verify connectivity from your application server to your Memcached server, a simple CURL request won’t do (much to my dismay).

Instead, you’ll need to use either Telnet or Netcat (nc) to poll the Memcached server for it’s stats, this can be done like so:

Memcached Telnet Connectivity Test

First, open a telnet session to your Memcached server on the appropriate port; by default Memcached listens on port 11211:

telnet memcached.yourdomain.com 11211

All being well, you should then be greeted with the following output:

Trying 208.67.222.124...
Connected to memcached.yourdomain.com.
Escape character is '^]'.

Typing “stats” should yield the following result:

stats
STAT pid 20781
STAT uptime 169659
STAT time 1480504602
STAT version 1.4.4
STAT pointer_size 64
STAT rusage_user 2.405634
STAT rusage_system 1.338796
STAT curr_connections 5
etc...

Memcached Netcat Connectivity Test

Netcat is a little nicer, in that you can connect and pull stats from your Memcached server using just the one command, run the following from your application server:

echo stats | nc memcached.yourdomain.com 11211

This should yield the following output and close automatically:

Trying 172.17.96.213...
Connected to memcached.yourdomain.com.
Escape character is '^]'.
stats
STAT pid 20781
STAT uptime 169659
STAT time 1480504602
STAT version 1.4.4
STAT pointer_size 64
STAT rusage_user 2.405634
STAT rusage_system 1.338796
STAT curr_connections 5
...
...
...
STAT total_items 536
STAT evictions 0
END
quit
Connection closed by foreign host.

There you have it, here’s how to test connectivity to your Memcached server using both Netcat and Telnet, if you have any queries be sure to use the comments section below.

1 thought on “How to Test Memcached Connectivity

  • December 4, 2020 at 5:05 pm
    Permalink

    echo stats | nc memcached.yourdomain.com 11211
    By using this it can start memcached but not closing automatically

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.