Home > Database > Redis > How to understand redis message queue

How to understand redis message queue

silencement
Release: 2019-06-17 15:13:12
Original
3939 people have browsed it

How to understand redis message queue

Queue

is a special linear table. The special thing is that it only allows deletion operations at the front end of the table. , and the insertion operation is performed at the back end (rear) of the table. Like the stack, the queue is a linear table with limited operations. The end that performs the insertion operation is called the tail of the queue, and the end that performs the deletion operation is called the head of the queue.

Message Queue

is a container that saves messages during their transmission. (redis tutorial)

Message queue in redis

In redis, you can use the built-in publish and subscribe commands to complete "message push" and "Message pulling" function implements message queue. However, one drawback of this method is that consumers must be online at the same time, otherwise consumption will be missed.

Message queue generally uses an independent cluster dedicated to message storage, which can be stored in memory or directly on disk. For example, the common ones: RabbitMQ, kafka, rocketMQ, ActiveMQ, zeromq, etc. They have different characteristics and adopt various implementations, which are suitable for message task distribution in various scenarios. But their essential role is the same as the Java "queue" in the single-instance environment mentioned above: a container that saves messages during the transmission of messages. It's just that it's converted to a "distributed" environment.

List (essentially a doubly linked list) and zset (ordered set) in redis can be used as containers for "message queues". With a little processing, a highly available "message queue" can be realized. The "lightweight" "message queue" implemented using redis has three major advantages:

1. Now redis has been widely used in major systems, and there is no need to introduce other third-party frameworks and APIs again.

2. And redis is based on memory storage, and the access speed of producers and consumers is very fast.

3. The capacity of the redis cluster can be expanded by adding instances.

If you meet the above three requirements, you can implement a simple "message queue".

The above is the detailed content of How to understand redis message queue. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template