Typorithm · easy

Lists as Queues

redis-listsredislistqueuelpush
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn Lists as Queues

0%

Data Types

A Redis list is an ordered sequence of strings. LPUSH prepends and RPUSH appends, so pairing LPUSH with RPOP gives a simple FIFO job queue.

Redis lists are ordered, linked sequences of string elements. You add from either end: LPUSH pushes onto the head (left) and RPUSH pushes onto the tail (right).

Combining LPUSH to add work and RPOP to take it off the other end yields first-in, first-out (FIFO) order — the classic job-queue pattern. LRANGE jobs 0 -1 reads every element from first to last.

LLEN reports the list's length. Because pushes and pops at the ends are O(1), lists are a fast, lightweight backbone for queues and recent-activity feeds.

01

Lists are ordered string sequences.

02

LPUSH prepends, RPUSH appends.

03

LPUSH + RPOP = FIFO queue.

LPUSH jobs "a"
RPUSH jobs "b"
LRANGE jobs 0 -1
RPOP jobs
LLEN jobs

Read the implementation

Connect each part of the code to the concept before you type.

1. Prepend (left)

LPUSH adds an element to the head (left) of the list, creating the list if it does not exist.

LPUSH jobs "a"

2. Append (right)

RPUSH adds an element to the tail (right) of the list — the opposite end from LPUSH.

RPUSH jobs "b"

3. Read all

LRANGE returns a slice by index; 0 to -1 spans from the first to the last element, i.e. the whole list.

LRANGE jobs 0 -1

4. Pop (right)

RPOP removes and returns the tail element; pairing LPUSH with RPOP gives FIFO queue order.

RPOP jobs

5. Length

LLEN returns the number of elements currently in the list.

LLEN jobs

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

Lists as Queues: Lesson & Practice · Typorithm | ApplyDjinn