In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "the introduction and usage of Redis list". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the introduction and usage of Redis list".
Redis list (List)
Reference: https://www.runoob.com/redis/redis-lists.html
Single-valued multiple value
1.lpush/rpush/lrange
Index 0 1 2 3 4
Lpush 1 2 3 4 5 5 4 3 2 1 first in and then out
Rpush 1 2 3 4 5 1 2 3 4 5
127.0.0.1 (integer) 5127.0.1 (integer) 5127.0.1 (LRANGE list01 0-11) "5" 2) "4" 3) "3" 4) "2" 5) "1" 127.0.1 rpush list02 (integer) 5127.0.1) 9736 > LRANGE list02 0-11) "1" 2) "2" 3) "3" 4) "4" 5) "5" 127.0.0.1 lpop/rpop 9736 > 2.
Lpop comes out from the head of the index
Rpop comes out from the end of the index.
127.0.0.1) lpop list01 "5" 127.0.1) lrange list01 0-11) "4" 2) "3" 3) "2" 4) "1" 127.0.1 lpop list02 "1" 127.0.1 LRANGE list02 0-11) "2" 2) 3) "4" 4) "5" 127.0.1) rpop list01 "1" 127.0. 0.1lrange list02 9736 > rpop list02 "5" 127.0.0.1 lrange list02 0-11) "4" 2) "3" 3) "2" 127.0.1) lrange list02 0-11) "2" 2) "3" 3) "4" 3.lindex index 127.0.0.1) lrange list01 0-11) "4" 2) "3" 3) "2" 127.0.0.1 : 9736 > lrange list02 0-11) "2" 2) "3" 3) "4" 127.0.0.1 lindex list02 9736 > lindex list01 1 "3" 127.0.1 lindex list02 1 "3" 4. Llen view the length of list 127.0.0.1 lindex list02 0-11) "4" 2) "3" 3) "2" 127.0.1 llen (integer) 35. Lrem key delete N of the same value
Delete 2 3s in this example
127.0.0.1 rpush list03 9736 > lrem list03 11 12 2 2 3 3 3 4 4 4 5 55 (integer) 15127.0.1 lrem list03 2 3 (integer) 2127.0.1 LRANGE list03 0-11) "1" 2) 1 "3)" 1 "4)" 2 "5)" 2 "6)" 2 "7)" 3 "8)" 4 "9)" 4 "10)" 4 "11 ) "5" 12) "5" 13) "5" 127.0.0.1 index 9736 > 6. Ltrim key start index end index Intercept a specified range of values and then assign them to key
This example intercepts 0 to 3 is 1 2 3 4, and then assigns a value to list01. List01 final 1 2 3 4
127.0.0.1 rpush list01 9736 > lrange list01 123 4 5 6 (integer) 6127.0.1 lrange list01 0-11) "1" 2) "2" 3) "3" 4) "4" 5) "5" 6) 6 "127.0.1 3OK127.0.0.1:9736 > lrange list01 0-11)" 1 "2)" 2 "3)" 3 "4)" 4 "7.
Pop up an element from the end of the source list to the header of the destination list
127.0.0.1) lrange list01 9736 > rpoplpush list01 list02 0-11) "1" 2) "2" 3) "3" 4) 4 "2) 2" 3) "3" 4) "4" 127.0.0.1 rpoplpush list01 list02 "4" 127.0.0.1) 9736 > lrange list02 0-11) "4" 2) "2" 3) "3" 4) "4" 127.0.0.1lset list01 9736 > lrange list01 0-11) "1" 2) "2" 3) "3" 8. Lset key index value127.0.0.1:9736 > lrange list01 0-11) "1" 2) "2" 3) "3" 127.0.0.1 xOK127.0.0.1:9736 > lrange list01 0-11) "x" 2) "2" 3) "3" 9.
Insert a value before / after the specified value
127.0.0.1) lrange list01 9736 > lrange list01 0-11) "x" 2) "2" 3) "3" 127.0.1) 9736 > linsert list01 before x a (integer) 4127.0.0.1) lrange list01 0-11) "a" 2) "x" 3) "2" 4) "3" 127.0.1) 9736 > linsert list01 after x b (integer) 5127.0.1) "2)" x "3)" b "4)" 2 "5)" 3 "
10. Performance Summary:
It is a string linked list that can be inserted and added by left right.
If the key does not exist, create a new linked list. If the key already exists, the new content is added. If all values are removed, the corresponding key disappears.
The operation of the linked list is very efficient both at the head and tail, but if it is for intermediate elements. The efficiency is very low.
Thank you for your reading, the above is the content of "introduction and usage of Redis list". After the study of this article, I believe you have a deeper understanding of the introduction and usage of Redis list, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.