Reading — step 1 of 3
Redis Lists
~1 min readLists
LPUSH & RPUSH — Building Lists
Redis lists are doubly-linked lists (or more precisely, quicklists — linked lists of ziplist pages). They support O(1) push/pop from both ends.
Commands
LPUSH key val [val ...]— push to head, return new lengthRPUSH key val [val ...]— push to tail, return new length
Multi-value Push
LPUSH mylist a b c pushes left-to-right: c ends up at the head.
The list becomes: [c, b, a]. Length returned: :3
Type Checking
If a key already exists as a string (or any non-list type), return:
-WRONGTYPE Operation against a key holding the wrong kind of value\r\n
This is Redis's type safety — each key has exactly one type.
Implementation
Use your language's deque/linked-list:
- Python:
collections.deque - JavaScript: Array (push/unshift)
- Go: slice or container/list
- C++:
std::deque
Track key types in a separate map: key_types[key] = "list".
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…