List API operations
-
-
-
- 1. Select the new database and get all the values in the database
- 2. LPUSH command
- 3. LRANGE command
- 4. RPUSH command
- 5. LPOP command
- 6, LINDEX command
- 7, LLEN command
- 8. LREM command
- 9, LTRIM command
- 10. RPOPLPUSH command
- 11. RPOPLPUSH command
- 12. LSET command
- 13, LINSERT before command
- 14. LINSERT after command
-
-
1. Select the new database and get all the values in the database
1. Select the database with index 2
127.0.0.1:16379[1]> select 2
OK
2. Get all the key information of the current 2 libraries
127.0.0.1:16379[2]> keys *
(empty list or set)
2. LPUSH command
1. Push the values zhangsan, lisi, wangwu into the list
127.0.0.1:16379[2]> LPUSH list zhangsan lisi wangwu
(integer) 3
3. LRANGE command
1. Get all the values in the list
127.0.0.1:16379[2]> LRANGE list 0 -1
1) "wangwu"
2) "lisi"
3) "zhangsan"
2. Get the value from 0 to 1 in the list
127.0.0.1:16379[2]> Lrange list 0 1
1) "wangwu"
2) "lisi"
4. RPUSH command
1. Push the value behind the list
127.0.0.1:16379[2]> RPUSH list zhaoliu
(integer) 4
2. Get all the values in the list
127.0.0.1:16379[2]> LRANGE list 0 -1
1) "wangwu"
2) "lisi"
3) "zhangsan"
4) "zhaoliu"
5. LPOP command
1. Take out the first value in the list
127.0.0.1:16379[2]> LPOP list
"wangwu"
127.0.0.1:16379[2]> LRANGE list 0 -1
1) "lisi"
2) "zhangsan"
3) "zhaoliu"
2. Take out the last value in the list
127.0.0.1:16379[2]> RPOP list
"zhaoliu"
127.0.0.1:16379[2]> LRANGE list 0 -1
1) "lisi"
2) "zhangsan"
3. Get all the values in the list
127.0.0.1:16379[2]> LRANGE list 0 -1
1) "lisi"
2) "zhangsan"
6, LINDEX command
1. Get the value of the specified index of 0 in the list
127.0.0.1:16379[2]> LINDEX list 0
"lisi"
127.0.0.1:16379[2]> LINDEX list 1
"zhangsan"
7, LLEN command
1. Get the length of the list
127.0.0.1:16379[2]> LLEN list
(integer) 2
2. Get all the values in the list
127.0.0.1:16379[2]> LRANGE list 0 -1
1) "lisi"
2) "zhangsan"
8. LREM command
1. Put multiple values in the list
127.0.0.1:16379[2]> LPUSH list liqi wangba gousheng
(integer) 5
127.0.0.1:16379[2]> LRANGE list 0 -1
1) "gousheng"
2) "wangba"
3) "liqi"
4) "lisi"
5) "zhangsan"
2. Remove the value specified in the list
127.0.0.1:16379[2]> LREM list 1 liqi
(integer) 1
127.0.0.1:16379[2]> LRANGE list 0 -1
1) "gousheng"
2) "wangba"
3) "lisi"
4) "zhangsan"
9, LTRIM command
1. Get all the values in the list
127.0.0.1:16379[2]> LRANGE list 0 -1
1) "gousheng"
2) "wangba"
3) "lisi"
4) "zhangsan"
2. Get all the values in the list 0 -1 interval
127.0.0.1:16379[2]> LTRIM list 0 -1
OK
3. Get all the values in the list
127.0.0.1:16379[2]> LRANGE list 0 -1
1) "gousheng"
2) "wangba"
3) "lisi"
4) "zhangsan"
4. Get all the values in the interval of list 0 2
127.0.0.1:16379[2]> LTRIM list 0 2
OK
127.0.0.1:16379[2]> LRANGE list 0 -1
1) "gousheng"
2) "wangba"
3) "lisi"
10. RPOPLPUSH command
1. Get all the values in the list
127.0.0.1:16379[2]> LRANGE list 0 -1
1) "gousheng"
2) "wangba"
3) "lisi"
2. Get the last value in the list and put it into mylist
127.0.0.1:16379[2]> RPOPLPUSH list mylist
"lisi"
127.0.0.1:16379[2]> LRANGE list 0 -1 ## 获取 list 中所有的值,list值没有了
1) "gousheng"
2) "wangba"
127.0.0.1:16379[2]> LRANGE mylist 0 -1 ## 获取 mylist 中所有的值
1) "lisi"
11. RPOPLPUSH command
1. Determine whether the list exists
127.0.0.1:16379[2]> EXISTS list
(integer) 1
12. LSET command
1. Get all the values in the list
127.0.0.1:16379[2]> LRANGE list 0 -1
1) "gousheng"
2) "wangba"
2. Set the value of the specified index of the list to overwrite
127.0.0.1:16379[2]> LSET list 0 lala
OK
127.0.0.1:16379[2]> LRANGE list 0 -1
1) "lala"
2) "wangba"
13, LINSERT before command
1. Get all the values in the list
127.0.0.1:16379[2]> LRANGE list 0 -1
1) "lala"
2) "wangba"
2. Batch settings and put values in the list
127.0.0.1:16379[2]> LPUSH list haha hehe
(integer) 4
3. Get all the values in the list
127.0.0.1:16379[2]> LRANGE list 0 -1
1) "hehe"
2) "haha"
3) "lala"
4) "wangba"
4. Set heihei before lala in the specified position of the list
127.0.0.1:16379[2]> LINSERT list before lala heihei
(integer) 5
5. Get all the values in the list
127.0.0.1:16379[2]> LRANGE list 0 -1
1) "hehe"
2) "haha"
3) "heihei"
4) "lala"
5) "wangba"
14. LINSERT after command
1. Set goushi at the specified position of the list, such as lala
127.0.0.1:16379[2]> LINSERT list after lala goushi
(integer) 6
2. Get all the values in the list
127.0.0.1:16379[2]> LRANGE list 0 -1
1) "hehe"
2) "haha"
3) "heihei"
4) "lala"
5) "goushi"
6) "wangba"
Writing is not easy to focus on three batter, I will always look forward to continuous output ... redis next type of operation Thank you!
Encourage you...