Master Redis Lists: Commands, Encoding, and QUICKLIST Explained
This article introduces Redis List as a linked collection of strings, explains its size limits, common CRUD commands, read operations, and dives into the underlying encodings—ZIPLIST, LINKEDLIST, and the hybrid QUICKLIST—highlighting when each is used.
What is Redis List?
Redis List is a collection of linked strings.
Limitations
Maximum number of elements is 2^32‑1 (4,294,967,295).
Use Cases
Lists serve as low‑level data structures for tasks such as storing queues of jobs or messages.
Common Operations
Operations focus on create, read, update, and delete.
Write Commands
LPUSH
Syntax: LPUSH key value [value ...] Adds elements to the head of the list and returns the list length.
127.0.0.1:6379> LPUSH listniuniu s1 s2 s3
(integer) 3
127.0.0.1:6379> LPUSH listniuniu s4
(integer) 4RPUSH
Syntax: RPUSH key value [value ...] Adds elements to the tail and returns the list length.
127.0.0.1:6379> RPUSH listniuniu s5
(integer) 5LPOP
Syntax: LPOP key Removes and returns the first element.
127.0.0.1:6379> LPOP listniuniu
"s4"RPOP
Syntax: RPOP key Removes and returns the last element.
127.0.0.1:6379> RPOP listniuniu
"s5"DEL
Syntax: DEL key [key ...] Deletes the key and returns the number of keys removed.
127.0.0.1:6379> DEL listniuniu
(integer) 1Read Commands
LLEN
Syntax: LLEN key Returns the length of the list.
127.0.0.1:6379> LLEN listniuniu
(integer) 3LRANGE
Syntax: LRANGE key start stop Returns elements between start and stop indices. Negative indices count from the end.
127.0.0.1:6379> LRANGE listniuniu 0 1
1) "s3"
2) "s2"
127.0.0.1:6379> LRANGE listniuniu -2 -1
1) "s2"
2) "s1"Underlying Implementation
Encoding Types (pre‑3.2)
Lists were encoded as either ZIPLIST (compact) or LINKEDLIST.
ZIPLIST is used when all strings are less than 64 bytes and the list has fewer than 512 elements.
If those conditions are not met, LINKEDLIST is used, storing each element as a separate node.
QUICKLIST (since 3.2)
QUICKLIST combines ZIPLIST and LINKEDLIST: each node of a linked list holds a ZIPLIST, giving the memory efficiency of ZIPLIST and the flexibility of LINKEDLIST.
ZIPLIST Optimizations
From Redis 7.0, ZIPLIST is replaced by LISTPACK, a more efficient compressed list representation.
Summary
Redis List is a double‑ended list data structure whose internal encoding switches between ZIPLIST, LINKEDLIST, and QUICKLIST to balance memory usage and performance.
NiuNiu MaTe
Joined Tencent (nicknamed "Goose Factory") through campus recruitment at a second‑tier university. Career path: Tencent → foreign firm → ByteDance → Tencent. Started as an interviewer at the foreign firm and hopes to help others.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
