Memcache Commands

Commands Cheat-Sheet

From https://lzone.de/cheat-sheet/memcached

The supported commands (the official ones and some unofficial) are documented in the doc/protocol.txt document.

Sadly the syntax description isn’t really clear and a simple help command listing the existing commands would be much better. Here is an overview of the commands you can find in the source (as of 19.08.2016):

Command
Description
Example

get

Reads a value

get mykey

set

Set a key unconditionally

set mykey <flags> <ttl> <size> <p>Ensure to use \r\n als line breaks when using Unix CLI tools. For example</p> printf "set mykey 0 60 4\r\ndata\r\n"

add

Add a new key

add newkey 0 60 5

replace

Overwrite existing key

replace key 0 60 5

append

Append data to existing key

append key 0 60 15

prepend

Prepend data to existing key

prepend key 0 60 15

incr

Increments numerical key value by given number

incr mykey 2

decr

Decrements numerical key value by given number

decr mykey 5

delete

Deletes an existing key

delete mykey

flush_all

Invalidate all items immediately

flush_all

flush_all

Invalidate all items in n seconds

flush_all 900

stats

Prints general statistics

stats

Prints memory statistics

stats slabs

Print higher level allocation statistics

stats malloc

Print info on items

stats items

stats detail

stats sizes

Resets statistics counters

stats reset

lru_crawler metadump

Dump (most of) the metadata for (all of) the items in the cache

lru_crawler metadump all

version

Prints server version.

version

verbosity

Increases log level

verbosity

quit

Terminate session

quit

Traffic Statistics

You can query the current traffic statistics using the command

You will get a listing which serves the number of connections, bytes in/out and much more.

Example Output:

Memory Statistics

You can query the current memory statistics using

Example Output:

If you are unsure if you have enough memory for your memcached instance always look out for the “evictions” counters given by the “stats” command. If you have enough memory for the instance the “evictions” counter should be 0 or at least not increasing.

Which Keys Are Used?

There is no builtin function to directly determine the current set of keys. However you can use the

command to determine how many keys do exist.

This at least helps to see if any keys are used. To dump the key names from a PHP script that already does the memcache access you can use the PHP code from 100days.de.

Last updated