当前位置:网站首页>Redis list detailed explanation of character types yyds dry goods inventory

Redis list detailed explanation of character types yyds dry goods inventory

2022-07-06 07:39:00 Jiangxiaolong's technology blog

Redis list list Detailed explanation of character types

1. List type common instructions

command meaning usage
LPUSH Insert data at the beginning lpush key value
RPUSH Insert data at the end rpush key value
LPOP Delete starting data lpop key
RPOP Delete end data rpop key
LRANGE see key data lrange key 0 -1

2. In the list key Middle write data

A list of key It can contain multiple pieces of data , list key It is similar to a database table , There are multiple pieces of data in it

In the list key There are two commands for writing data in ,RPUSH and LPUSH

rpush Means to write from the right , It can be understood as writing data from the end to the inside

lpush Means to write from the left , It can be understood as writing data from the beginning to the inside

Grammar format :LPUSH key value

​ RPUSH key value

1. Write data from the end to the inside 
127.0.0.1:6379> RPUSH list1 A
(integer) 1
127.0.0.1:6379> RPUSH list1 B 
(integer) 2
127.0.0.1:6379> RPUSH list1 C
(integer) 3

2. Write data from the beginning to the inside 
127.0.0.1:6379> LPUSH list1 a
(integer) 4
127.0.0.1:6379> LPUSH list1 b
(integer) 5
127.0.0.1:6379> LPUSH list1 c
(integer) 6

3. Check all the values in the list 
 The order should be cba ABC,RPUSH Every time a data is written, it is inserted at the end ,LPUSH Writing a data is always inserted at the beginning 
127.0.0.1:6379> LRANGE list1 0 -1
1) "c"
2) "b"
3) "a"
4) "A"
5) "B"
6) "C"

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.

3. Delete list key One of the data in

Delete key Data from LPOP and RPOP name

LPOP The command starts at the beginning and deletes , Grammar format :LPOP key

RPOP The command starts at the end and deletes , Grammar format :RPOP key

1. Use LPOP Delete the first piece of data 
 You can see c Been deleted , because c At the top 
127.0.0.1:6379> LPOP list1
"c"
127.0.0.1:6379> LRANGE list1 0 -1
1) "b"
2) "a"
3) "A"
4) "B"
5) "C"

2. Use RPOP Delete the bottom piece of data 
 You can see C Been deleted , because C At the bottom 
127.0.0.1:6379> RPOP list1
"C"
127.0.0.1:6379> LRANGE list1 0 -1
1) "b"
2) "a"
3) "A"
4) "B"


     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.

4. view list key The data of

redis list key The first one is 0, The second is 1

Grammar format :lrange key From the first few lines To which line

1. Check the data of Article 1 and Article 2 
127.0.0.1:6379> LRANGE list1 0 1
1) "b"
2) "a"

2. Check the data of Article 1 and Article 3 
127.0.0.1:6379> LRANGE list1 0 2
1) "b"
2) "a"
3) "A"

3. View all data 
127.0.0.1:6379> LRANGE list1 0 -1
1) "b"
2) "a"
3) "A"
4) "B"

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
原网站

版权声明
本文为[Jiangxiaolong's technology blog]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131908081337.html