A detailed introduction to the Redis List list

  • 2020-05-17 06:55:07
  • OfStack

A detailed introduction to the Redis List list

The Redis list is a simple list of strings, sorted in insertion order. You can add 1 element to the header (left) or tail (right) of the list

A list can contain a maximum of 232-1 elements (4294967295, each with more than 4 billion elements).

The instance


redis 127.0.0.1:6379> LPUSH runoobkey redis
(integer) 1
redis 127.0.0.1:6379> LPUSH runoobkey mongodb
(integer) 2
redis 127.0.0.1:6379> LPUSH runoobkey mysql
(integer) 3
redis 127.0.0.1:6379> LRANGE runoobkey 0 10

1) "mysql"
2) "mongodb"
3) "redis"

In the above example we used LPUSH to insert three values into a list named runoobkey.

Redis list command

The basic commands for listing are listed below:


1  BLPOP key1 [key2 ] timeout 
   Move out and get the first in the list 1 An element,   If there are no elements in the list, the list will be blocked until the wait timeout or pop-up element is found. 

2  BRPOP key1 [key2 ] timeout 
   Move out and get the end of the list 1 An element,   If there are no elements in the list, the list will be blocked until the wait timeout or pop-up element is found. 

3  BRPOPLPUSH source destination timeout 
   Pops up from the list 1 To insert the pop-up element into another 1 And return it;   If there are no elements in the list, the list will be blocked until the wait timeout or pop-up element is found. 

4  LINDEX key index 
   Gets the elements in the list by index 

5  LINSERT key BEFORE|AFTER pivot value 
   Insert the element before or after the element in the list 

6  LLEN key 
   Get list length 

7  LPOP key 
   Move out and get the first in the list 1 An element 

8  LPUSH key value1 [value2] 
   will 1 Two or more values are inserted into the head of the list 

9  LPUSHX key value 
   will 1 Values are inserted into the existing list header 

10 LRANGE key start stop 
   Gets the list of elements in the specified range 

11 LREM key count value 
   Remove list element 

12 LSET key index value 
   Sets the value of the list element through the index 

13 LTRIM key start stop 
   right 1 The list is pruned (trim) , that is, let the list keep only the elements within the specified interval, and all elements outside the specified interval will be deleted. 

14 RPOP key 
   Remove and get the end of the list 1 An element 

15 RPOPLPUSH source destination 
   Remove the end of the list 1 And add that element to another 1 List and return 

16 RPUSH key value1 [value2] 
   Add to the list 1 Two or more values 

17 RPUSHX key value 
   Add a value to an existing list 

The above is Redis List list detailed explanation, if you have any questions please leave a message or to this site community exchange discussion, thank you for reading, hope to help you, thank you for your support to this site!


Related articles: