Quick Reference · in-memory data structure store

redis cheat sheet

Every key points to one of a handful of data structures — string, list, hash, set, sorted set, and a few specialists. Learn what shape a key holds and the right command family follows naturally.

connect / inspect keys & expiry write read admin / ops destructive most common

Distilled & cross-checked against: redis.io/docs/latest/commands · redis.io cheat sheet · quickref.me · GeeksforGeeks · dev.to command series · oneuptime.com ops guides

One key, one of six shapes — pick the structure, the commands follow
key "user:501" String "Hello world" · SET / GET / INCR List [a, b, c] · LPUSH / RPUSH / LRANGE Hash {name:"Max"} · HSET / HGET / HGETALL Set {a,b,c} unique · SADD / SMEMBERS Sorted Set members ranked by score · ZADD + SPECIALIST STRUCTURES, SAME "ONE KEY, ONE SHAPE" RULE Stream append-only log · XADD / XREAD Bitmap bit ops on a string · SETBIT HyperLogLog approx. unique count · PFADD Geo lat/lon as a sorted set · GEOADD Every key also carries: TTL EXPIRE / TTL / PERSIST work on any type above
01Connect & CLIredis-cli
02Keys — Genericworks on any type
03Expiry & TTLstructure · auto-cleanup
04Stringstext, numbers, JSON blobs, counters
05Listsordered · queues & stacks
06Hashesfield → value maps, like a mini object
07Setsunordered, unique members
08Sorted Setsunique members, ranked by score
09Bitmaps & HyperLogLogbit tricks & approximate counting
10Streamsappend-only event log
11Geospatiala sorted set under the hood
12Transactionsadmin · queue & run atomically
13Pub/Subadmin · fire-and-forget messaging
14Persistenceadmin · RDB & AOF
15Replicationadmin · primary/replica
16Server & Configmeta · inspect & tune
17Scriptingadmin · server-side Lua
18Danger Zonewhole-database operations
19Data Types at a Glancewhat a value can be

Core five

Stringtext, number, or binary blob up to 512MB
Listordered, insert at either end
Hashfield→value map, like a flat object
Setunordered, unique members
Sorted Setunique members ranked by a float score

Specialists

Streamappend-only log with consumer groups
Bitmapa string, addressed bit-by-bit
HyperLogLogprobabilistic distinct-count, ~12KB fixed
Geolat/lon points, backed by a sorted set
JSON (module)native JSON via RedisJSON, if loaded
Time Complexity CheatsheetBig-O of common ops
GET / SETO(1)
LPUSH / RPUSH / LPOP / RPOPO(1)
LRANGE key 0 -1O(N)
HSET / HGETO(1)
SADD / SISMEMBERO(1)
ZADD / ZSCOREO(log N)
ZRANGE / ZRANGEBYSCOREO(log N + M)
KEYS patternO(N) — avoid
SCAN (per call)O(1) amortized

Three structures worth visualizing

Where reads and writes actually happen on the shapes developers reach for most, based on the official Redis data type documentation.

List — push/pop from either end

LPUSH and RPUSH add at opposite ends; LPOP/RPOP remove from the end they name. LRANGE never mutates.

a b c d LPUSH/LPOP RPUSH/RPOP

Hash — field/value pairs

One key holds many fields, each with its own value. HGET touches one field without loading the rest.

user:501 name "Max" age 32 city "Pune"

Sorted Set — ranked by score

Members stay ordered by score automatically. ZRANGE walks low→high; ZREVRANGE flips it — the standard leaderboard pattern.

bob : 42 max : 88 alex : 120 ZRANGE walks this direction (low score → high)

Worth memorizing

KEYS blocksnever run KEYS in production — use SCAN, it's cursor-based & non-blocking
SET ... EXsets a value + TTL in one atomic round trip, no separate EXPIRE needed
DEL vs UNLINKUNLINK reclaims memory in a background thread — safer for big keys
APPEND auto-createsappending to a missing key just creates it, no error
INCR is atomicsafe for counters even with many concurrent clients
SET ... NX"set if not exists" — the building block for a simple distributed lock
single-threaded coreone command runs fully before the next starts — no partial-write races
WATCH + MULTI/EXECoptimistic locking — EXEC returns null if a watched key changed first