The Interrogation Queue
Concept:
Redis Lists are ordered collections that support push/pop from both ends — making them natural queues. In production, they power job queues (workers RPOP tasks that producers LPUSH), activity feeds (LPUSH new events, LRANGE to display recent ones), and message buffers. Unlike a database table, a Redis list handles thousands of push/pop operations per second with zero overhead. The key insight: if you need ordered, fast, temporary data — use a list.
Detective Indecks:
Three suspects in the lobby. They all claim innocence, but someone's lying. I need to question them one by one, in order.
REDIS:
Sounds like you need a queue, detective. A first-in, first-out system. Redis Lists are perfect for this—they maintain order like a proper lineup.
Detective Indecks:
Talk to me. How do I line them up?
REDIS:
Think of a List like a lineup against the wall. You can add suspects to either end: `LPUSH` puts them at the front of the line, `RPUSH` puts them at the back. Want to follow standard procedure? Use `RPUSH interrogation:queue "suspect_alpha"` to add them to the back.
Detective Indecks:
And when I'm ready to bring someone in?
REDIS:
`LPOP interrogation:queue` takes the first person in line. `RPOP` takes the last. For proper interrogation protocol, you want `LPOP`—first come, first served. Fair and methodical.
Detective Indecks:
Perfect. No cutting in line, no favorites. Just clean, orderly justice.
REDIS:
Want to check how many are still waiting? `LLEN interrogation:queue` gives you the count. Want to see who's next without removing them? `LINDEX interrogation:queue 0` shows the first person.
Detective Indecks:
Let's put this system to work. Time to build that queue.
Example Code:
LPUSH interrogation:queue "suspect_charlie"
LPOP interrogation:queue
Your Assignment
Three suspects just walked in: `suspect_alpha`, `suspect_bravo`, and `suspect_charlie`. Add them to the interrogation queue in that order (alpha first, charlie last), then bring the first suspect in for questioning.
Redis Console
redis>