Reference · Cheat sheet
Pick the type whose hot-path op is cheapest. Print it, pin it.
| Type | Reach for it when… | Cheap ops | O(N) traps |
|---|---|---|---|
| String | value, counter, flag, bitmap | GET/SET/INCR O(1) | — |
| Hash | a record with fields | HGET/HSET O(1)/field | HGETALL |
| List | queue / stack (touch the ends) | LPUSH/RPUSH/LPOP/RPOP O(1) | LINDEX, LRANGE 0 -1 |
| Set | unique membership, tags | SADD/SISMEMBER O(1) | SMEMBERS, SINTER O(N·M) |
| Sorted set | ordered by a score | ZSCORE O(1) · ZADD/ZRANK O(log N) · ZRANGE O(log N + M) | — |
SISMEMBER), never a scanned list.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.
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