Using Redis as a Queue
Redis also functions as a queue if you want to use it that way. Using the operations lpush
, lpop
, rpush
, rpop
, you can simulate LIFO or FIFO operations. Let's run redis-cli
for a quick demo before we jump into integrating Redis into a node application.
Let's start by using lpush
and lpop
to simulate a LIFO stack. We push things onto the stack and the pop them off in LIFO order.
Simple! For our demo, we're going to be more concerned with using Redis as a queue. So let's simulate a quick FIFO queue interaction.
We lpush
things into our queue and rpop
to retrieve our items in FIFO order.
Again, super simple! So let's translate this into utilizing this for a message queue in node!