Redis to implement reliable queues

Source: Internet
Author: User
Reliable queues can be implemented with Redis Brpop or Blpop commands.
Its command format such as: Brpop|blpop list1 list2 list3 ... timeout parameters: List set timeout blocking time, when the timeout is 0 is to indicate blocking time unrestricted.
Return value: Returns an element that exists in List1 or List2 or list3 (because it is the first Non-empty list that is checked from the list1–> list2–> list3 order).

such as:> brpop mylist1 0 1) "Mylist1" 2 "dd" NOTE: The first element is the key of the pop-up element, and the second element is value. Empty queues:>del Mylist1 when Brpop|blpop returns an element to the client, it removes the element from the list.
This means that the element exists only in the context of the client: If the client's process of handling the return element crashes, the element is lost forever. This can lead to some problems in applications that we want to be more reliable messaging systems.
At this point, look at the Brpoplpush command, which is a variant of blpop, which adds the element to a target list before passing it back to the client.
Brpoplpush is a blocked version of Rpoplpush. Command format: Brpoplpush list_source list_destination timeout element was popped from List_source and pressed into the list_destination. When List_source contains elements, the command behaves exactly like Rpoplpush. When the List_source is empty, Redis will block the connection until another client push element enters or reaches the timeout time limit.
Timeout 0 can be used to block clients indefinitely.> lrange list1 0-1 (empty list or set)> Lrange mylist 0-1 1) "D" 2) "C" 9> Brpoplpush MyList LiSt1 0 "C"> lrange list1 0-1 1) "C",> Lrange mylist 0-1 1) "D"

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: 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.