Cheat sheet · No. X

redis-cli.

Redis is a single-threaded dictionary in RAM. Every command is atomic and nothing runs concurrently — which is why one slow command, or one KEYS *, stalls everyone behind it.

Printable One A4 page
PLATE — redis-cliFIG. X user:1 "ada" cart:1 […] hits 4096TTL 60 SET k v EX 60 · SCAN, never KEYSone page, pinned to the wall.
The reference
STRINGS
SET k v
Write (overwrites)
SET k v EX 60
Write with 60s TTL
SET k v NX
Only if absent (a lock primitive)
GET k
Read
INCR counter
Atomic +1
INCRBY counter 10
Atomic +n
MGET k1 k2
Batch read
HASHES & LISTS
HSET user:1 name ada age 30
Set fields
HGET user:1 name
One field
HGETALL user:1
Every field
LPUSH q job1
Push to head
BRPOP q 5
Pop from tail, block up to 5s — a work queue
LRANGE q 0 -1
Whole list (-1 = last)
SETS & SORTED SETS
SADD tags go redis
Add members
SISMEMBER tags go
Membership test, O(1)
SMEMBERS tags
All members
ZADD lb 100 alice
Add with score
ZINCRBY lb 5 alice
Bump a score
ZRANGE lb 0 9 REV WITHSCORES
Top 10 — a leaderboard
TTL & KEYSPACE
EXPIRE k 300
Set TTL on an existing key
TTL k
Seconds left (-1 none, -2 missing)
PERSIST k
Remove the TTL
SCAN 0 MATCH 'user:*' COUNT 100
Page through keys without blocking
TYPE k EXISTS k
What and whether
UNLINK k
Delete, free memory in background
PUB/SUB & PIPELINES
SUBSCRIBE events
Listen (fire-and-forget — no replay)
PUBLISH events "hi"
Send to current subscribers
MULTI … EXEC
Queue commands, run atomically
redis-cli --pipe < cmds.txt
Bulk-load: one round-trip, not thousands
redis-cli -r 10 -i 1 INFO clients
Repeat 10×, 1s apart
DEBUG
redis-cli -h host -p 6379 -a pass
Connect
PING
Liveness — expect PONG
INFO memory
used_memory, fragmentation
MEMORY USAGE k
Bytes held by one key
DBSIZE
Key count
SLOWLOG GET 10
Recent slow commands
redis-cli --bigkeys
Scan for the largest keys
Field notes
KEYS blocks the world

KEYS * walks the entire keyspace while every other client waits. Use SCAN with MATCH — it pages through with a cursor and never stalls the server.

TTL speaks in negatives

TTL returns -1 for a key with no expiry and -2 for a key that does not exist. Easy to misread when you are in a hurry.

UNLINK big keys

DEL frees memory synchronously — on a huge hash that is a visible pause. UNLINK returns immediately and frees in a background thread.

MONITOR is for dev

It echoes every command the server processes and can halve throughput. In production, reach for SLOWLOG GET and INFO instead.

Tip: hit ⌘P / Ctrl-P to save this single page as a PDF or print it for the wall.

Found this useful?