Memcached Common Commands - CodeSwordsman

Text-protocol read and write commands, stats metrics, memory and connection flags, hit-rate and slab monitoring, with flush_all warnings.

Memcached 1.6Updated 2026-10-3021 commands

Connection & Stats

Open an interactive session with telnet and run commands line by line

telnet 127.0.0.1 11211

Fetch key statistics in one shot, handy for scripts

printf 'stats\r\nquit\r\n' | nc 127.0.0.1 11211

Show connections, hits, memory and evictions

stats

Show item counts, age and evictions per slab class

stats items

Show slab memory allocation and usage to spot fragmentation

stats slabs

Print a table of items, hits and evictions per slab

memcached-tool 127.0.0.1:11211 display

Data Commands

Store a key: flags 0, TTL 900 seconds, 5-byte payload on the following line

set user:42 0 900 5
admin

TTLs beyond 30 days must be passed as a Unix timestamp instead of a relative seconds value

Fetch a value; request several keys with one get command

get user:42

Store only when the key is absent, useful as a cache stampede placeholder

add user:42 0 900 5

Overwrite only when the key already exists

replace user:42 0 900 5

Remove a key; DELETED means success

delete user:42

Atomic increment of a decimal string value; use decr to decrement

incr counter 1
Risky

Invalidate every cached item; running this in production causes a cache stampede

flush_all

Startup & Memory

Run in the background with 512 MB memory, 1024 connections and all interfaces

memcached -m 512 -c 1024 -l 0.0.0.0 -p 11211 -d

Raise the per-item size limit above the 1 MB default, considering memory impact

memcached -I 4m

Enable slab reassignment to relieve uneven utilization across item sizes

memcached -o slab_reassign,slab_automove=2

Start with slab_automove at 1; level 2 reclaims more aggressively

Confirm the running memory cap, connection limit and item size limit

stats settings

Hit Rate & Monitoring

Read the core counters; hit rate equals get_hits divided by cmd_get

stats | grep -E 'cmd_get|get_hits|get_misses'

Show the distribution of item counts by size bucket

stats sizes

Requires startup with -o track_sizes; tracking adds overhead

In debug mode, watch the read requests currently being served

watch fetchers

Reset counters so post-change baselines are clean

stats reset

This website uses cookies to ensure you get the best experience on our website. Privacy Policy.