redis of the type commonly used Methods List

redis of the type commonly used Methods List

format:

存---LPUSH key value [value ...]
取--LRANGE key start stop
  1. lpush key value [value ...] one or more values ​​are inserted into the head of the list

    127.0.0.1:6379> lpush plf panlifu 
    (integer) 1
    127.0.0.1:6379> lpush plf lt
    (integer) 2
    127.0.0.1:6379> lpush plf xs
    (integer) 3
    127.0.0.1:6379> lpush plf cd
    (integer) 4
    127.0.0.1:6379> lrange plf 0 1
    1) "cd"
    2) "xs"
    127.0.0.1:6379> lrange plf 0 3
    1) "cd"
    2) "xs"
    3) "lt"
    4) "panlifu"
  2. lrange key start stop get a list of the elements within the specified range

    127.0.0.1:6379> lpush plf panlifu 
    (integer) 1
    127.0.0.1:6379> lpush plf lt
    (integer) 2
    127.0.0.1:6379> lpush plf xs
    (integer) 3
    127.0.0.1:6379> lpush plf cd
    (integer) 4
    127.0.0.1:6379> lrange plf 0 1
    1) "cd"
    2) "xs"
    127.0.0.1:6379> lrange plf 0 3
    1) "cd"
    2) "xs"
    3) "lt"
    4) "panlifu"
  3. The first element blpop key [key ...] timeout and get out of the list, if the list is not a list of the elements will block until a timeout or wait until the pop-up element can be found

    127.0.0.1:6379> blpop plf  timeout 1
    1) "plf"
    2) "cd"
    127.0.0.1:6379> lrange plf 0 4
    1) "xs"
    2) "lt"
    3) "panlifu"
  4. brpop key [key ...] timeout and get out of the last element of the list, if the list is not a list of the elements will block until a timeout or wait until the discovery may pop elements.

    127.0.0.1:6379> lrange plf 0 4
    1) "xs"
    2) "lt"
    3) "panlifu"
    127.0.0.1:6379> brpop plf timeout 1
    1) "plf"
    2) "panlifu"
    127.0.0.1:6379> lrange plf 0 4
    1) "xs"
    2) "lt"
  5. brpoplpush source destination timeout pop a value from the list, the pop-up element into another list and returns it; if the list does not list element will block until the wait timeout, or pop-up element may be found so far. ?

    127.0.0.1:6379> brpoplpush plf lt timeout 10
    (error) ERR wrong number of arguments for 'brpoplpush' command
    127.0.0.1:6379> 
    
  6. lindex key index to obtain the list of elements by index

    127.0.0.1:6379> lrange plf 0 3
    1) "xs"
    2) "lt"
    127.0.0.1:6379> lindex plf 1
    "lt"
    127.0.0.1:6379> lindex plf 0
    "xs"
    127.0.0.1:6379> 
  7. linsert key BEFORE | AFTER pivot value insert elements in the list of elements before or after

    
    127.0.0.1:6379> lrange plf 0 3
    1) "xs"
    2) "lt"
    127.0.0.1:6379> linsert plf after lt hehe
    (integer) 3
    127.0.0.1:6379> lrange plf 0 3
    1) "xs"
    2) "lt"
    3) "hehe"
    127.0.0.1:6379> linsert plf before lt hehe
    (integer) 4
    127.0.0.1:6379> lrange plf 0 3
    1) "xs"
    2) "hehe"
    3) "lt"
    4) "hehe"
  8. llen key to get a list length

    127.0.0.1:6379> lrange plf 0 3
    1) "xs"
    2) "hehe"
    3) "lt"
    4) "hehe"
    127.0.0.1:6379> llen plf
    (integer) 4
  9. The first element lpop key removed and get a list of

    127.0.0.1:6379> lrange plf 0 3
    1) "xs"
    2) "hehe"
    3) "lt"
    4) "hehe"
    127.0.0.1:6379> llen plf
    (integer) 4
    127.0.0.1:6379> lpop plf
    "xs"
    127.0.0.1:6379> lrange plf 0 3
    1) "hehe"
    2) "lt"
    3) "hehe"
  10. lpushx key value header will be inserted into a value list already exists

```shell
127.0.0.1:6379> lpushx hehe hello
(error) WRONGTYPE Operation against a key holding the wrong kind of value
127.0.0.1:6379> lpushx plf hello
(integer) 4
127.0.0.1:6379> lrange plf 0 5
1) "hello"
2) "hehe"
3) "lt"
4) "hehe"
```
  1. lrem key count value remove list elements, count the number of times

    127.0.0.1:6379> lrange plf 0 5
    1) "hello"
    2) "hehe"
    3) "lt"
    4) "hehe"
    127.0.0.1:6379> lrem plf 2 hehe
    (integer) 2
    127.0.0.1:6379> lrange plf 0 5
    1) "hello"
    2) "lt"
  2. lset key index value by setting the index value of the list element

    127.0.0.1:6379> lrange plf 0 5
    1) "hello"
    2) "lt"
    127.0.0.1:6379> lset plf 0 gunkai
    OK
    127.0.0.1:6379> lrange plf 0 5
    1) "gunkai"
    2) "lt"
  3. ltrim key start stop for a list of trim (trim), that is, make a list of only the specified retention element within the range of elements within the range of not specified will be deleted.

    127.0.0.1:6379> lrange plf 0 10
     1) "gunkai"
     2) "lt"
     3) "1"
     4) "2"
     5) "3"
     6) "4"
     7) "5"
     8) "6"
     9) "7"
    10) "8"
    127.0.0.1:6379> ltrim plf 0 3
    OK
    127.0.0.1:6379> lrange plf 0 10
    1) "gunkai"
    2) "lt"
    3) "1"
    4) "2"
  4. rpop key removes the last element of the list, the return value of the element removed.

    127.0.0.1:6379> lrange plf 0 10
    1) "gunkai"
    2) "lt"
    3) "1"
    4) "2"
    127.0.0.1:6379> rpop plf
    "2"
    127.0.0.1:6379> lrange plf 0 10
    1) "gunkai"
    2) "lt"
    3) "1"
  5. rpoplpush source destination removes the last element of the list, and adds the element to another list and returns

    127.0.0.1:6379> lrange plf 0 10
    1) "gunkai"
    2) "lt"
    3) "1"
    127.0.0.1:6379> rpoplpush plf lt
    "1"
    127.0.0.1:6379> lrange plf 0 10
    1) "gunkai"
    2) "lt"
    127.0.0.1:6379> lrange lt 0 10
     1) "1"
  6. rpush key value [value ...] to add one or more values ​​in a list

    127.0.0.1:6379> lrange plf 0 5
    1) "gunkai"
    2) "lt"
    127.0.0.1:6379> rpush plf  1 2 3 4 5 6 7 8
    (integer) 10
    127.0.0.1:6379> lrange plf 0 10
     1) "gunkai"
     2) "lt"
     3) "1"
     4) "2"
     5) "3"
     6) "4"
     7) "5"
     8) "6"
     9) "7"
    10) "8"
  7. rpushx key value adding value to an existing list

    127.0.0.1:6379> rpushx test_key 1
    (integer) 0
    127.0.0.1:6379> lrange test_key 0 1
    (empty list or set)

Summary: ending x key is to determine whether the presence, absence can not be set, to set presence. R represents the start with a plurality of values ​​can be added simultaneously

Guess you like

Origin www.cnblogs.com/plf-Jack/p/11080463.html
Recommended