In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
List types and operations
List is a linked list structure, the main function is push, pop, get all the values in a range, etc., the key in the operation is understood as the name of the linked list. The list type of Redis is actually a doubly linked list with each child element of type String. We can add and delete elements from the head or tail of the list through push and pop operations, so that the list can be used as both a stack and a queue.
lpush
Add a string element to the head of the list corresponding to key
//press world then hello127.0.0.1:6379> lpush mylist world(integer) 1127.0.0.1:6379> lpush mylist hello(integer) 2lrange// 0 for the first element,-1 for the last element 127.0.0.1: 6379> lrange mylist 0 -11) "hello"2) "world" push
Add string data to the end of the list corresponding to key
127.0.0.1:6379> rpush mylist chenxl(integer) 3127.0.0.1:6379> lrange mylist 0 -11) "hello"2) "world"linsert
Add a string before or after a specific position in the list corresponding to key
127.0.0.1:6379> lpush countList one(integer) 1127.0.0.1:6379> lpush countList two(integer) 2127.0.0.1:6379> linsert countList before two three(integer) 3127.0.0.1:6379> lrange countList 0 -11) "three"2) "two"3) "one"lset
Sets the value of the element in the list for the specified index
//Change subscript 1, i.e. the second element, to 2.5127.0.0.1:6379> lset countList 1 2.5OK127.0.0.1:6379> lrange countList 0 -11) "three"2) "2.5"3) "one"lrem
Delete n elements identical to value from the list corresponding to key, n lrange countList 0 -11) "one"2) "one"3) "one"4) "three"5) "2.5"6) "one" 127.0.0.1: 6379> lrem countList 2 one(integer) 2127.0.0.1:6379> lrange countList 0 -11) "one"2) "three"3) "2.5"4) "one"ltrim
Retains data within the range of values specified by key
127.0.0.1:6379> lpush numList one(integer) 1127.0.0.1:6379> lpush numList two(integer) 2127.0.0.1:6379> lpush numList three(integer) 3127.0.0.1:6379> lpush numList four(integer) 4127.0.0.1:6379> lpush numList five(integer) 5127.0.0.1:6379> ltrim numList 1 3OK127.0.0.1:6379> lrange numList 0 -11) "four"2) "three"3) "two"lpop
Delete an element from the head of the list and return the deleted element
127.0.0.1:6379> lrange mylist 0 -11) "hello"2) "world"3) "chenxl"127.0.0.1:6379> lpop mylist "hello"127.0.0.1:6379> lrange mylist 0 -11) "world"2) "chenxl"rpop
Remove an element from the end of the list and return the deleted element
127.0.0.1:6379> rpush mylist one(integer) 1127.0.0.1:6379> rpush mylist two(integer) 2127.0.0.1:6379> rpush mylist three(integer) 3127.0.0.1:6379> lrange mylist 0 -11) "one"2) "two"3) "three"127.0.0.1:6379> rpop mylist "three"127.0.0.1:6379> rpop mylist "two"127.0.0.1:6379> lrange mylist 0 -11) "one"rpoplpush
Remove elements from the end of the first list and add them to the head of the second list
127.0.0.1:6379> lrange mylist01 0 -11) "one"2) "two"3) "three"127.0.0.1:6379> lrange mylist02 0 -11) "four"2) "five"3) "six"127.0.0.1:6379> rpoplpush mylist01 mylist02"three"127.0.0.1:6379> lrange mylist01 0 -11) "one"2) "two"127.0.0.1:6379> lrange mylist02 0 -11) "three"2) "four"3) "five"4) "six"lindex
Returns the element at index in a list named key
127.0.0.1:6379> lrange mylist 0 -11) "one"2) "two"3) "three"127.0.0.1:6379> lindex mylist 1"two"llen
Returns the length of the list corresponding to the key
127.0.0.1:6379> lrange mylist 0 -1 1) "one"2) "two"3) "three"127.0.0.1:6379> llen mylist(integer) 3
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.