redis list of data types --- list

I. Overview

  1. redis list is a simple list of strings, sort insertion order
  2. You can add an element to the head of the list (on the left) or tails (to the right)
  3. A list can contain up to 2 ^ 32-1 elements (each element of a list of more than 4 billion).


Two, redis list of key types of settings

  • Command name: LPUSH
  • 语法:lpush key value [value……]
  • Features:
    • 1) one or more values ​​of key value inserted into the list header.
    • 2) If the value plurality of values, the values ​​of the respective value in the order from left to right are sequentially inserted into the header.
    • 3) operates as atomic operations, if the key does not exist, an empty list is created and executed lpush operation.
  • return value:
    • 1) After executing the command lpush length list; if the key is not a list, an error is returned

 

  • Command name: lpushx
  • Syntax: lpush key value
  • Features:
    • 1) The value of the key value inserted into the list header, if and only if the key is present and is a list.
    • 2) and lpush command Conversely, when the key is not present, lpushx command does nothing.
  • return value:
    • 1) After executing the command lpushx, length of the list

 

  • Command name: linsert
  • 语法:linsert key BEFORE|AFTER pivot value
  • Features:
    • 1) values ​​among the key value inserted into the list, the value is located before or after the pivot.
    • 2) When there is no key in the pivot list, does not perform any operation.
    • 3) When the key is not present, it is considered key empty list, no action.
  • return value:
    • 1) If, after the command is executed successfully, return insertion, the length of the list;
    • 2) If no pivot, return -1;
    • 3) If the key does not exist or is empty list, return 0

 

  • Command name: LSET
  • Syntax: lset key index value
  • Features:
    • 1) The key index list set index value of the element is to value.
    • 2) When the index parameter out of range, or an empty list (key not present) LSET, an error is returned.
    • 3) When the key is not present, it is considered key empty list, no action.
  • return value:
    • 1) Operation successful return ok, otherwise it returns an error message

 

  • Command name: RPUSH
  • 语法:rpush key value [value……]
  • Features:
    • 1) The values ​​of one or more key value inserted into the list of the tail.
    • 2) If the value plurality of values, the values ​​of the respective value from left to right are sequentially inserted into the end of the table.
    • 3) operates as atomic operations, if the key does not exist, an empty list is created and executed rpush operation.
  • return value:
    • 1) After rpush command execution, the length of the list;
    • 2) If the key is not a list, it returns an error

 

  • Command name: rpushx
  • Syntax: rpush key value
  • Features:
    • 1) The value of the key value inserted into the list header, if and only if the key is present and is a list.
    • 2) and rpush command Conversely, when the key is not present, what rpushx command does nothing.
  • return value:
    • 1) After executing the command rpushx, length of the list

Three, redis list of key types of queries

  • Command name: lindex
  • Syntax: lindex key index
  • Features:
    • 1) returns a list of key, the subscript index of the element, the first element 0, -1 for the last element.
  • return value:
    • 1) the subscript index list element.
    • 2) If the value of the range interval is not on the list of the index parameter (out of range), returns nil

 

  • Command name: LLEN
  • Syntax: llen key
  • Features:
    • 1) returns the length of the key list.
  • return value:
    • 1) If the key does not exist, then the key is interpreted as an empty list, return 0.
    • 2) a list of key length.

 

  • Command name: lrange
  • Syntax: lrange key start stop
  • Features:
    • 1) returns the list of key elements in the specified interval, the interval to the specified start and stop offsets.
    • 2) subscript (index) to both start and stop parameters 0 as a substrate.
    • 3) negative index may also be used to -1 is the last element of the list
  • return value:
    • 1) a list of the elements contained in the specified range.
    • 2) out of range index value does not cause error

Fourth, delete redis list of key types

  • Command name: lpop
  • Syntax: lpop key
  • Features:
    • 1) Removes and returns the first element of the list of key
  • return value:
    • 1) the first element of the list.
    • 2) When the key is not present, returns nil

 

  • Command name: lrem
  • Syntax: lrem key count value
  • Features:
    • 1) The count value of the parameter, the removal of the list elements is equal to the parameter value.
    • 2) count> 0: starting from the end of the header to the table search, equal to the value element is removed, the number of count; count <0: starting from the head end of the table to the table search, equal to the value element is removed, an amount of the absolute value of the count; count = 0: all value equal to the value in the table is removed
  • return value:
    • 1) The number of elements removed

 

  • Command name: LTRIM
  • Syntax: ltrim key start stop
  • Features:
    • 1) a list of trim (trim), that is to say, make a list of retaining only the elements within the specified range, elements within the range of not specified will be deleted
  • return value:
    • 1) command is successful, the return OK.

 

  • Command name: RPOP
  • Syntax: rpop key
  • Features:
    • 1) removing the key and returns a list of the last element
  • return value:
    • 1) the last element of the list.
    • 2) When the key is not present, returns nil

 

  • Command name: rpoplpush
  • Syntax: rpoplpush source destination
  • Features:
    • 1) This command atom within a time, perform the following two actions: the last element (the last element) in the source list popup, and returned to the client; the source element is inserted into the pop-up list of destination, as destination list head elements
  • return value:
    • 1) is ejected elements

Fifth, blocking operation redis list of key types

  • Command name: BLPOP
  • Syntax: blpop key [key ......] timeout
  • Features:
    • 1) blpop version is blocking blocking (blocking) pop primitive, lpop a list of commands when a given list is not available when any element of the pop-up, the connection will be blocked blpop command, know to wait for a timeout or found to pop Until element
  • return value:
    • 1) If there is no long element is ejected, it returns a nil and wait a specified time.
    • 2) On the contrary, returns a list containing the two elements, the first element is a key element belongs be ejected, the second element is the value of the element is popped

 

  • Command name: brpop
  • Syntax: brpop key [key ......] timeout
  • Features:
    • 1) brpop addition to the different elements of pop and blpop position, the other consistent performance
  • return value:
    • 1) If there is no long element is ejected, it returns a nil and wait a specified time.
    • 2) On the contrary, returns a list containing the two elements, the first element is a key element belongs be ejected, the second element is the value of the element is popped

 

  • Command name: brpoplpush
  • Syntax: brpoplpush source destination timeout
  • Features:
    • 1) brpoplpush is rpoplpush blocking version, when given a list of source is not empty, brpoplpush performance and rpoplpush same.
    • 2) When the source list is empty, brpoplpush command blocked connections until wait timeout, or other source of a client command is executed lpush or rpush.
    • 3) timeout parameter timeout accepts a digital value as seconds. Timeout parameter is set to 0 for blocking time can be extended indefinitely (block indefinitely)
  • return value:
    • 1) If there is no long element is ejected, it returns a nil and wait a specified time.
    • 2) On the contrary, returns a list containing the two elements, the first element is a key element belongs be ejected, the second element is the value of the element is popped

Guess you like

Origin www.cnblogs.com/lxhyty/p/11390033.html