Lists

Lists #

18 commands. Lists are stored as an indexed sequence; two of these commands rebuild the whole list.

CmdRWSyntaxReturnsExample → reply
LPUSHWLPUSH KEY VALUE [VALUE ...]integer new lengthLPUSH q a b → 2
RPUSHWRPUSH KEY VALUE [VALUE ...]integer new lengthRPUSH q c → 3
LPOPWLPOP KEYbulk head element, null if emptyLPOP q → b
RPOPWRPOP KEYbulk tail element, null if emptyRPOP q → c
LLENRLLEN KEYinteger element countLLEN q → 1
LINDEXRLINDEX KEY indexbulk, null if out of rangeLINDEX q 0 → a
LRANGERLRANGE KEY start stoparray (inclusive, negative offsets from the end)LRANGE q 0 -1 → [a]
LSETWLSET KEY index VALUE+OKLSET q 0 z → OK
LTRIMWLTRIM KEY start stop+OKLTRIM q 0 0 → OK
RPOPLPUSHWRPOPLPUSH source destinationbulk moved element, null if source emptyRPOPLPUSH q backup → z
LINSERTWLINSERT KEY BEFORE|AFTER pivot VALUEinteger new length; 0 pivot absent; -1 key absentLINSERT q BEFORE z y → 2
LREMWLREM KEY count VALUEinteger elements removedLREM q 0 z → 1
LKEYEXISTSRLKEYEXISTS KEYinteger 0/1 — does the list existLKEYEXISTS q → 1
LCLEARWLCLEAR KEYinteger elements removedLCLEAR q → 1
LMCLEARWLMCLEAR KEY [KEY ...]integer lists removedLMCLEAR a b → 2
LEXPIREWLEXPIRE KEY secondsinteger 1/0LEXPIRE q 600 → 1
LEXPIREATWLEXPIREAT KEY unixTimeinteger 1/0LEXPIREAT q 1767225600 → 1
LTTLRLTTL KEYinteger seconds left, -1 noneLTTL q → 599

Notes #

  • LPUSH q a b produces [b, a] — each element is pushed to the head in turn, as in Redis.
  • LREM KEY count VALUE: count > 0 removes from the head, count < 0 from the tail, count = 0 every occurrence.
  • LINSERT and LREM are O(n) and are not transactional. The storage layer has no primitive for them, so the handler reads the list, clears it, and rewrites it (restoring the TTL). It happens inside one Raft apply, so no other client observes a partial list, but a backend failure mid-rebuild leaves the list truncated. Do not use them on long lists in a hot path — prefer LTRIM or bounded queues.
  • There is no LPERSIST: the handler is not registered. LCLEAR/LMCLEAR delete the list and its TTL.
  • No blocking commands. BLPOP/BRPOP are deliberately not registered: a blocking read inside the Raft apply loop either stalls the log or consumes the queue without a rollback path.
  • LRANGE with start > stop answers an empty array; negative indexes count from the tail.