Redis Publisher/Subscriber Model
This lesson explains the concepts behind using Redis as a queue.
What is a message queue?
A message queue is a type of temporary storage for messages. The sender, also known as publisher, sends messages to the queue. The messages remain in the queue until a receiver also known as a subscriber, is ready to read the messages. The main use case for a message queue is when there are some larger jobs that need to be processed. The sender sends the jobs to a queue instead of directly sending it to the receiver. The receiver picks each job, one by one, and processes it.
Let’s say we are booking movie tickets on a website. There are a few things that should be done immediately, like selecting the seats, payment, etc. But a few things, like sending tickets via email, may take time and are not required to be done immediately. These tasks that time and are not required to be done immediately can be added to a queue and can be processed one by one.
How Redis is used as a message queue?
As we discussed earlier, Redis can also be used as a message queue. The publisher can publish to only one channel, although a channel may have multiple subscribers. A subscriber can subscribe to one or more channels.
Create a free account to view this lesson.
By signing up, you agree to Educative's Terms of Service and Privacy Policy