Database / REDIS
What is the difference between a Redis List and Sorted Set for queues?
Both can back a queue, but they fit different queue semantics depending on whether strict FIFO insertion order or a computed priority should determine processing order.
| List (LPUSH/RPOP) | Sorted Set (ZADD/ZPOPMIN) |
| Strict insertion-order FIFO (or LIFO with matching push/pop ends). | Ordered by an explicit score, which can represent priority, a timestamp, or any custom ranking. |
| Simple, minimal overhead per operation. | Slightly more overhead, since it maintains sorted order via a skip list. |
| Good fit for a plain task queue where order of arrival is all that matters. | Good fit for a priority queue, delayed queue (score = due time), or any case needing reordering. |
| BLPOP/BRPOP provide blocking pop for worker patterns. | ZPOPMIN/ZPOPMAX support similar patterns, plus range queries by score. |
The deciding question is usually: does processing order need to be anything other than strict arrival order? If yes — priority levels, a scheduled/delayed queue, or reordering based on some external factor — a Sorted Set's score gives that flexibility directly; if the queue is genuinely just first-in-first-out, a List is simpler and has less overhead per operation for the same result.
More Related questions...
