List data structure of redis --redis (5)

redis's List is a special list

 

 

 
 
 
There are more basic operations
LPUSH: on the far left of the list (the header) is inserted into the element, if the header element is present, then the original element will be pushed to the next position of the header (left)
RPUSH: At the far right of the list (footers) insert elements, if present footer element, the element will be pushed to the original position of the tail on a table (right)
LPOP: Remove header elements
RPOP: Remove the end of the table element
 

 

 

BRPOP: This operation is generally used to block the queue, the listener will use this command redis list, if the list element, the element will be removed footer, if not, it will continue to loop listens redis list.
 
With these basic operations can imitate stack, queue data structure, and operation of blocking queue:
 

 

 

Stack: LPUSH + FPOP: Insert elements from the header, the header elements having (last out)
Queue: LPUSH + RPOP: inserting the header element, taking element (FIFO) from the end of the table
Blocking queue: LPUSH + BRPOP: inserting the header element, cycle monitor list, taking the end of the table element.
 
Internet usage scenarios:
Weibo, a focus on the big V, when the big V sent a message, the message first cache. Then the user's attention to the big V message queue using PUSH added to a user's message queue, when a user refreshes the message, this information will be loaded.

Guess you like

Origin www.cnblogs.com/lockXie/p/11784301.html