quick memcache testing and troubleshooting

Here’s a quick way to test your new memcached setup. At first it’s a bit confusing to understand that memcache has no knowledge of what keys it stores, just whether or not it has a particular key. Unlike relational databases, you can’t query memcache and get all of the values it has. You have to know the key that you want to fetch before you ask memcache about it. Let’s ask it the value for the key foo:

telnet memcacheserver 11211
Connected to
Escape character is '^]'.
get foo

It returns nothing, so it doesn’t have any value for that key. The key foo is unset. Let’s set it:

set foo 0 0 3

When you set a key like this, follow the syntax “set <keyname> <flag> <ttl> <storebytes>”. In this case our key is foo, we have no important flags (0), there is no expiration of the key value pair (0), and the data we are about to store is 3 bytes (aka 3 characters). Let’s fetch it now:

get foo
VALUE foo 0 3

It returns the value of key foo as bar. Now delete it:

delete foo

Now another, this time the key is “foobar”, and the data is a 12 byte string “barbarbarbar”:

set foobar 0 0 12
get foobar
VALUE foobar 0 12
delete foobar
telnet> close
Connection closed.

get memcache statistics

To obtain some stats about a memcached process, use nc to talk directly to it:

# echo "stats" | nc -w 1  11211
STAT pid 1750
STAT uptime 29481383
STAT time 1369781775
STAT version 1.4.5
STAT pointer_size 64
STAT rusage_user 6974.991909
STAT rusage_system 13000.624488
STAT curr_connections 10
STAT total_connections 132871296
STAT connection_structures 1674
STAT cmd_get 227296759
STAT cmd_set 113549712
STAT cmd_flush 0
STAT get_hits 221783239
STAT get_misses 5513520
STAT delete_misses 0
STAT delete_hits 0
STAT incr_misses 36444
STAT incr_hits 19304751
STAT decr_misses 3
STAT decr_hits 19367598
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 26222582271
STAT bytes_written 25905663432
STAT limit_maxbytes 67108864
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 0
STAT bytes 27010093
STAT curr_items 366610
STAT total_items 113554333
STAT evictions 0
STAT reclaimed 5291352