Skip to content
LPOP, RPOP & LLEN
step 1/3

Reading — step 1 of 3

Pop & Length

~1 min readLists

LPOP, RPOP & LLEN

Now let's remove elements from lists.

Commands

  • LPOP key — remove and return head. Returns bulk string or $-1\r\n if empty/missing
  • RPOP key — remove and return tail
  • LLEN key — return list length as integer (:0 for non-existing key)

Auto-delete Empty Lists

When all elements are popped, Redis automatically deletes the key. The key simply ceases to exist — EXISTS key returns :0, TYPE key returns +none.

Queue & Stack Patterns

  • Queue (FIFO): RPUSH + LPOP (add right, take left)
  • Stack (LIFO): LPUSH + LPOP (add left, take left)

These patterns are why Redis lists are so popular for job queues and message buffers.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…