Reference · Cheat sheet

Data structures by complexity

Pick the type whose hot-path op is cheapest. Print it, pin it.

From lesson 0002See also glossary

Type → use → cost

TypeReach for it when…Cheap opsO(N) traps
Stringvalue, counter, flag, bitmapGET/SET/INCR O(1)
Hasha record with fieldsHGET/HSET O(1)/fieldHGETALL
Listqueue / stack (touch the ends)LPUSH/RPUSH/LPOP/RPOP O(1)LINDEX, LRANGE 0 -1
Setunique membership, tagsSADD/SISMEMBER O(1)SMEMBERS, SINTER O(N·M)
Sorted setordered by a scoreZSCORE O(1) · ZADD/ZRANK O(log N) · ZRANGE O(log N + M)

The heuristic

Big-key rule

One key holding a giant collection = O(N) commands stall the shared thread and DEL is O(N). Bound collections, iterate with *SCAN, delete with UNLINK.

Encoding note

Small hashes/sets/zsets use a compact listpack (or intset) below config thresholds, so O(N) on them is trivial and memory-cheap. Redis auto-converts to hashtable/skiplist past the threshold. Inspect with OBJECT ENCODING key.

← lesson 0002 · Source: Redis Docs — Data types