Video in progress
How do you build a simple job queue out of a Redis List?
The producer adds to the head of the list with LPUSH, the worker takes from the tail with BRPOP. BRPOP is blocking: if the queue is empty, it waits until an element arrives or the timeout expires.
📖 Answer
# producer
LPUSH jobs:email '{"to":"ali@mail.uz"}'
# worker
BRPOP jobs:email 5 # waits up to 5 seconds
If you add on the left and take from the right, you get FIFO.
This setup is enough for small jobs, but you need to know its limit: if the worker takes an element and crashes while processing it, the element is gone, because it has already left the list. A partial fix is to use LMOVE (formerly RPOPLPUSH) to move the element into a "processing" list and remove it when the job finishes.
If you need acknowledgments (ack), retries and several consumer groups, use Redis Streams or a full broker (RabbitMQ, Kafka) instead of a List.
Sign up to mark studied questions and save your progress.