Redis implements a simple message queue

Source: Internet
Author: User

1. Q: What is Message Queuing?

A: is a linked list of messages and is an asynchronous processing engine.

2. Q: What are the benefits?

A: Not only can increase the load of the system, but also can improve the data loss caused by network congestion.

3. Q: What are the uses?

A: Mail sending, SMS sending, data form submission, image generation, video conversion, log storage, etc.

4, Q: What software?

A: ZeroMQ, Posix, Squirrelmq, Redis, qdbm, Tokyo tyrant, HTTPSQS, etc. (under Linux platforms).

5, Q: How to achieve?

A: As the name implies, first queue, after the team, first throw the data into the message queue, and then according to the corresponding key to obtain data (out of the team).

6. Q: Can redis do Message Queuing?

A: First, Redis is designed to be cached, but because of its own nature it can be used to do Message Queuing, it has a few blocking API can be used, it is these blocking API to have the ability to do Message Queuing, in addition, Other features of Message Queuing, such as FIFO (first-in, first-out), are also easy to implement, requiring only a list object to fetch data from scratch, to plug data from the tail, and redis to do Message Queuing thanks to its list object Blpop Brpop interface and some interfaces of pub/sub (Publish/subscribe) , they are all blocked, so they can be used as message queues.

7, Q: How to do (based on thinkphp)?

A: 7.1 Installation of Redis, process (slightly);

7.2 Installation Php-redis extension, process (slightly);

7.3 Post Code

Figure 1 The queue

Figure 2 Queued Results

Figure 3 The Team

Figure 4 The results of the team

Figure 5 Complete code

8, Summary: Redis's Lpush command inserts one or more values into the list header is the opposite of Rpush and Rpush; the Rpop command is used to overflow and return the last element of the list to the opposite of Lpop.

Redis implements a simple message queue

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.