4. Basic Redis commands-list, basic redis-list
1. The list type is implemented using a double linked list. Therefore, if you want to add elements to both ends, the time complexity is O (1 ), the faster the element gets closer to the two ends. However, the cost is that accessing elements through indexes is slow.
2. the maximum number of fields that each key can hold is 2 ^ 32-1. The variable type used internally to store the number of fields should be Integer, because an Integer is 4 bytes and each byte is 8 bits, Which is exactly 32 bits, the maximum number is 2 ^ 32-1 (including 0 ).
2.1. The index starts from 0.
3. Add the LPUSH key value to the left of the queue and return the length of the queue element. 127.0.0.1: 6379> lpush list 123
(Integer) 3
127.0.0.1: 6379> lpush list 123
(Integer) 4 add multiple elements at a time 127.0.0.1: 6379> LPUSH list 11 12 13
4. The LRANGE key start end is returned to the elements between [start, end] in the queue, which start from 0 like the prime group and contain the end bit. If start> end, an empty list 127.0.0.1: 6379> LRANGE list 3 2 is returned.
(Empty list or set) If end> LLEN key, all lists 127.0.0.1: 6379> LLEN list (integer) 4 are returned.
127.0.0.1: 6379> LRANGE list 0 8
1) "4"
2) "3"
3) "2"
4) "1" If end =-1 LRANGE key 0-1 all lists are returned 127.0.0.1: 6379> LRANGE list 0-1
1) "4"
2) "3"
3) "2"
4) "1" reads data in reverse order, and start end is smaller than 0 127.0.0.1: 6379> LRANGE list 0-1
1) "7"
2) "6"
3) "5"
4) "4"
5) "3"
6) "2"
7) "1"
127.0.0.1: 6379> LRANGE list-1-1
1) "1"
127.0.0.1: 6379> LRANGE list-2-1
1) "2"
2) "1"
5. Length of the list obtained by LLEN key: 127.0.0.1: 6379> LLEN list (integer) 4
6. Add the RPUSH key value to the right of the queue and return the element length 127.0.0.1: 6379> RPUSH list-1.
(Integer) 5
127.0.0.1: 6379> LRANGE list 0-1
1) "4"
2) "3"
3) "2"
4) "1"
5) "-1"
7. LPOP/rpop pop elements on the left/right
127.0.0.1: 6379> LPOP list "4" 127.0.0.1: 6379> LRANGE list 0-1 1) "3"
2) "2"
3) "1"
4) "-1"
127.0.0.1: 6379> RPOP list "-1" 127.0.0.1: 6379> LRANGE list 0-1
1) "3"
2) "2"
3) "1"
8. LREM key count value: delete count elements with values. When count> 0, delete count elements with values from the left. When count <0, delete it from the right. | count | value when count = 0, delete all elements whose values are value 127.0.0.1: 6379> LRANGE list 0-1
1) "1"
2) "1"
3) "1"
4) "1"
5) "1"
6) "3"
7) "2"
127.0.0.1: 6379> LREM list 0 1 (integer) 5127.0.0.1: 6379> LRANGE list 0-1
1) "3" 2) "2"
9. Add the value 127.0.0.1: 6379> LRANGE list 0-1 to the index of the LSET key index value.
1) "13"
2) "12"
3) "11"
4) "7"
5) "6"
6) "5"
7) "4"
8) "3"
9) "2"
10) "1" 127.0.0.1: 6379> LSET list 3 8 9 10 cannot set multiple values at the same time
(Error) ERR wrong number of arguments for 'lset' command 127.0.0.1: 6379> lset list 3 8 OK 127.0.0.1: 6379> LRANGE list 0-1
1) "13"
2) "12"
3) "11"
4) "8"
5) "6"
6) "5"
7) "4"
8) "3"
9) "2"
10) "1"
10. LINDEX list 0 obtains the index value 127.0.0.1: 6379> LINDEX list 0 "13"
12. LTRIM key start end removes data except (start, end. Retain [start, end] data, including start, end 127.0.0.1: 6379> LRANGE list 0-1
1) "5"
2) "4"
3) "3"
4) "2"
5) "1"
127.0.0.1: 6379> LTRIM list 1 3
OK
127.0.0.1: 6379> LRANGE list 0-1
1) "4"
2) "3"
3) "2"
13. LINSET key BEFORE | AFTER inserting value inserts data
127.0.0.1: 6379> LRANGE list 0-1
1) "4"
2) "3"
3) "2"
127.0.0.1: 6379> LINSERT list before 4 5 (integer) 4127.0.0.1: 6379> LRANGE list 0-1
1) "5"
2) "4"
3) "3"
4) "2"
127.0.0.1: 6379> LINSERT list after 2 0 (integer) 5127.0.0.1: 6379> LRANGE list 0-1
1) "5"
2) "4"
3) "3"
4) "2"
5) "0" If there are multiple identical partitions, start 127.0.0.1: 6379> LRANGE list 0-1 from the first on the left.
1) "4"
2) "5"
3) "4"
4) "3"
5) "2"
6) "0"
127.0.0.1: 6379> LINSERT list after 4 3 (integer) 7127.0.0.1: 6379> LRANGE list 0-1 1) "4"
2) "3"
3) "5"
4) "4"
5) "3"
6) "2"
7) "0" BEFORE also starts from the first one on the left.
127.0.0.1: 6379> LINSERT list Before 3 9 (integer) 8127.0.0.1: 6379> LRANGE list 0-1
1) "4"
2) "9"
3) "3"
4) "5"
5) "4"
6) "3"
7) "2"
8) "0"
14. RPOPLPUSH source destination-list type: transfers an element from one list to another. An element pops up from the right of the source. Then, LPUSH to destination is added to RPOPLPUSH source destination for internal implementation: def rpoplpush (source, destination) value = RPOP source LPUSH destination value return value
15. Summary A. The list can be used as A stack, LPUSH/LPOP, RPUSH/rpop B, and list. LPUSH/RPOP or RPUSH/LPOP