redis List type command

In Redis, List is an ordered, repeatable data structure that supports inserting, deleting, and retrieving elements. The following are some common Redis List type commands:

  1. LPUSH: Inserts one or more values ​​from the left side of the list.
    LPUSH key value1 value2 ...
    

Among them, keyis the key name of the list, value1, value2etc. are the values ​​to be inserted.

Example:

LPUSH mylist "world"
LPUSH mylist "hello"

After executing the above command, the contents of the list mylist are:

1) "hello"
2) "world"

The above command first inserts "value2" to the left side of the mylist list, and then inserts "value1". Insertion order is the reverse of the order in which parameters are passed.

With the LPUSH command, you can create a list in Redis and add new elements to it from the left side of the list. This allows you to use lists to implement stack-like functionality (first in, last out), or as a message queue to store and process message data.

  1. RPUSH: Inserts one or more values ​​from the right side of the list.
    RPUSH key value1 value2 ...
    

Example:

RPUSH mylist "hello"
RPUSH mylist "world"

After executing the above command, the contents of the list mylist are:

1) "hello"
2) "world"

The above command first inserts "value1" to the right side of the mylist list, and then inserts "value2". The insertion order is the same as the order in which parameters are passed.

With the RPUSH command, you can create a list in Redis and add new elements from the right side of the list. This allows you to use lists to implement queue-like (first-in-first-out) functionality, or as a message queue to store and process message data.

  1. LPOP: Removes and returns the first element on the left side of the list.

    LPOP key
    
  2. RPOP: Removes and returns the first element on the right side of the list.

    RPOP key
    
  3. LLEN: Get the length of the list (number of elements).

    LLEN key
    
  4. LRANGE: Get the elements within the specified range of the list.

    LRANGE key start stop
    
  5. LINDEX: Gets the element at the specified index position in the list.

    LINDEX key index
    
  6. LSET: Sets the element value at the specified index position in the list.

    LSET key index value
    
  7. LREM: Removes the specified number of matching elements from the list.

    LREM key count value
    
  8. LTRIM: Keep elements within the specified range of the list and delete other elements.

    LTRIM key start stop
    
  9. BLPOP: Blockingly removes and returns the first element in the list, blocking and waiting if the list is empty.

    BLPOP key1 key2 ... timeout
    
  10. BRPOP: Blockingly removes and returns the last element in the list, blocking and waiting if the list is empty.

    BRPOP key1 key2 ... timeout
    
  11. LINSERT: Inserts a new element before or after the specified element in the list.

    LINSERT key BEFORE|AFTER pivot value
    
  12. RPOPLPUSH: Removes and gets the rightmost element of a list and adds it to the left of another list.

    RPOPLPUSH source destination
    

Guess you like

Origin blog.csdn.net/drhnb/article/details/132176440
Recommended