Introduction to the
  • A list can contain one or more items, each in order of where they are pushed into the list
  • Lists contain items that can be duplicated; they do not have to be unique
  • Stores multiple repeatable packets in an ordered fashion, the function equivalent to a queue operation in Java
The list of operations
  • LPUSH key value [value …] Push one or more values to the left of the list. The command returns the current number of items in the list after the new value has been pushed

    127.0.0.1:6379> lpush list 12 3 (integer) 3Copy the code
  • LPOP Key removes and returns the right-most item in the list

    127.0.0.1:6379> lpop list
    "3"
    127.0.0.1:6379> lpop list
    "2"
    Copy the code
  • RPUSH key value [value …] Push one or more values to the right of the list. The command returns the current number of items in the list after the new value has been pushed

    127.0.0.1:6379> rpush list 4 5 6
    (integer) 6
    Copy the code
  • RPOP Key removes and returns the left-most item in the list

    127.0.0.1:6379> rpop list
    "6"
    127.0.0.1:6379> rpop list
    "5"
    127.0.0.1:6379> rpop list
    "4"
    127.0.0.1:6379> rpop list
    "1"
    Copy the code
  • LLEN Key Returns the length of the list key, that is, the number of list items contained in the list

    127.0.0.1:6379> llen list (integer) 0 127.0.0.1:6379> lpush list 12 3 4 5 6 (integer) 6Copy the code
  • LINDEX key index Returns a list item in a specified index index in the key list without deleting the original value. The index index can be positive or negative

    27.0.0.1:6379> lindex list 2
    "4"
    127.0.0.1:6379> llen list
    (integer) 6
    Copy the code
  • LRANGE key start stop Returns all key items in the range from start to stop without deleting the original values. Both index parameters can be positive or

Negative 127.0.0.1:6379> lrange list 1 5 1) “5” 2) “4” 3) “3” 4) “2” 5) “1” 127.0.0.1:6379> llen list (integer) 6

Insert and delete operations
  • LSET key index value Sets the list item on the list key index to value. If the setting succeeds, the command returns OK. If the index parameter exceeds the range of the list index, an error is returned

    127.0.0.1:6379> lrange list 1 1 1) "5" 2) "4" 3) "3" 4) "2" 5) "1" 127.0.0.1:6379> lset list 1 5x OK 127.0.0.1:6379> Lset list 100 5x (error) ERR index out of range 127.0.0.1:6379> lrange list 1 5 1) "5x" 2) "4" 3) "3" 4) "2" 5) "1" 'Copy the code
  • LINSERT key BEFORE | AFTER the pivot value according to the command invocation passing options BEFORE or AFTER options, insert the value the value to the specified list items BEFORE or AFTER the pivot. When pivot does not exist in the list key, nothing is done

    127.0.0.1:6379> linsert list  before 4 400
    (integer) 7
    127.0.0.1:6379> lrange  list 1 10
    1) "5x"
    2) "400"
    3) "4"
    4) "3"
    5) "2"
    6) "1"
    Copy the code
  • LREM key count value Removes list items equal to value based on the value of parameter count • If count > 0, search from the top of the table to the bottom of the table. Select * from abs(count); select * from abs(count); select * from abs(count); The remove all list items with value command returns the number of removed list items that are equal to value

  • LTRIM Key start stop Trim a list so that only the list items within the specified index range are kept and all other list items outside the range are removed

Delete it. Both indexes can be positive or negative, If the command is executed successfully, OK 127.0.0.1:6379> lrange list 1 6 1) “5x” 2) “400” 3) “4” 4) “3” 5) “2” 6) “1” 127.0.0.1:6379> ltrim list 1 3 OK 127.0.0.1:6379> lrange list 1 6 1) “400” 2) “4”

Blocking pop-up operation
  • BLPOP key [key …] The timeout command accesses each list given in left-to-right order and pops the left-most item of the first non-empty list. If all given lists are empty, the client will block until the wait times out, or until there is an item that can be popped up

  • BRPOP key [key …] The timeout command accesses each of the given lists in left-to-right order and pops the first item from the right-most end of the non-empty list. If all of the given lists are empty, the client will block until the wait times out, or until there is an item that can pop up. Setting the timeout parameter to 0 means block forever

    127.0.0.1:6379> blpop list 0
    1) "list"
    2) "9"
    (3.18s)
    Copy the code
  • BLPOP/BRPOP first-come, first-served rule If multiple clients are blocked on a list at the same time, then when new values are pushed to the list, the server follows the first-come rule

The first in first service principle returns the new value to the earliest blocked client first