Test for Redis Operations list

Source: Internet
Author: User

Lpush Press data from the head

127.0.0.1:6379> lpush listname value1 (integer) 1//returns the current length of the list 127.0.0.1:6379> Lpush listname value2
(integer) 2127.0.0.1:6379> lpush listname value2 (integer) 3//successfully added duplicate elements, indicating that list is repeatable Lpushx When the list of given listname is present, insert data from above, otherwise do nothing127.0.0.1:6379> lpushx LISTNAME0 value (integer) 0 RPUSHX inserts the data from below when the list of given listname is present, otherwise it does nothing127.0.0.1:6379> rpushx LISTNAME0 value (integer) 0 Lrange from head to tail (stack) Gets the data for the specified index rangeLrange listname 0-1 127.0.0.1:6379> lrange listname 0 0
1) "value2"
127.0.0.1:6379> lrange listname 0 1
1) "value2" 2) "value2" 127.0.0.1:6379> lrange listname 0-1
1) "value2"
2) "value2" 3) "value1" Rpush pressing elements from the rear127.0.0.1:6379> Rpush ListName Value0
(integer) 4
127.0.0.1:6379> Lrange ListName 0-1
1) "value2"
2) "value2"
3) "value1" 4) "Value0" Linsert Middle InsertionLinsert listname before value1 value2 insert value1 in front of value2127.0.0.1:6379> Linsert listname before Value0 value--
(integer) 5
127.0.0.1:6379> lrange listname 0-1
1) "value2"
2) "value2"3) "Value1"4) "value--"//Successful insertion5) "Value0" 127.0.0.1:6379> Linsert listname before value2 value--(integer) 6 (successfully inserted)127.0.0.1:6379> lrange listname 0-11) "value--"//insert above the first matching value found from top to bottom2) "value2"
3) "value2"
4) "Value1"
5) "value--"6) "Value0" 127.0.0.1:6379> Linsert listname before value--value+
(integer) 7127.0.0.1:6379> lrange listname 0-11) "value+"//insert above the first matching value found from top to bottom2) "value--"
3) "value2"
4) "value2"
5) "Value1"
6) "value--" 7) "Value0" 127.0.0.1:6379> Linsert listname before Value7 value8 (integer) -1//cannot find Value7 insert unsuccessful 127.0.0.1 :6379> Lrange ListName 0-1
1) "Value+"
2) "Valuenew"
3) "value2"
4) "value2"
5) "Value1"
6) "value--" 7) "Value0" LSet Update the value of the element that specifies the foot tag127.0.0.1:6379> LSet listname 1 valuenewok127.0.0.1:6379> lrange listname 1 each) "Valuenew" 127.0.0.1:6379> LSet L Istname 7 Value7 (Error) ERR index out of range//when the pin is out of bounds, the error will be prompted Lrem Deletes the specified number of values as an element of the specified valueLrem listname x value//First add a value2127.0.0.1:6379> linsert listname before Valuenew value2
(integer) 8
127.0.0.1:6379> Lrange ListName 0-1
1) "Value+"
2) "value2"
3) "Valuenew"
4) "value2"
5) "value2"
6) "Value1"
7) "value--" 8) "VALUE0"//Remove 1 value2127.0.0.1:6379> lrem listname 1 value2 (integer) 1//the topmost value2 was removed 127.0.0.1:6379 > Lrange listname 0-1
1) "Value+"
2) "Valuenew"
3) "value2"
4) "value2"
5) "Value1"
6) "value--" 7) "Value0" Lindex Returns the element of the specified corner labelLindex listname x127.0.0.1:6379> lindex listname 0
"Value+" 127.0.0.1:6379> lindex listname 7 (Nil)//out of index return Nill127.0.0.1:6379> lindex listname-1when the "VALUE0"//PIN is negative, start looking from the bottom of the list127.0.0.1:6379> lindex listname-7"Value+" 127.0.0.1:6379> lindex listname-8 (nil) Lpop pops an element from the head, returns the element value and deletes127.0.0.1:6379> lpop listname "value+" 127.0.0.1:6379> lpop listname
"Valuenew"
127.0.0.1:6379> Lrange ListName 0-1
1) "value2"
2) "value2"
3) "Value1"
4) "value--" 5) "Value0" Rpop pops an element from the tail, returns the element value and deletes127.0.0.1:6379> Rpop ListName
"Value0"
127.0.0.1:6379> Lrange ListName 0-1
1) "value2"
2) "value2"
3) "value1" 4) "value--" LTrim Remove a PIN element other than the specified rangeLTrim listname x1 X2 Only retains elements from x1~x2 127.0.0.1:6379> LTrim listname 0-1
Ok
127.0.0.1:6379> Lrange ListName 0-1
1) "value2"
2) "value2"
3) "value1" 4) "value--" 127.0.0.1:6379> ltrim listname 1 2OK//successfully deleted the PIN is not within 1-2 of the element, here deleted 0 elements of the foot marked 3 two 127.0.0.1:6379> LR Ange ListName 0-1
1) "value2" 2) "value1" 127.0.0.1:6379> ltrim listname 1 0OK//delete elements other than 1-0, remove all elements 127.0.0.1:6379> keys *//list is cleared ( Empty list or set)// BULK Insert four data, note version issues, low-version Redis does not support BULK INSERT127.0.0.1:6379> lpush listname value--value1 value2 value2 (integer) 4127.0.0.1:6379> lrange listname 0-1
1) "value2"
2) "value2"
3) "value1" 4) "value--" 127.0.0.1:6379> lpush listname1 value value+ value-(integer) 3127.0.0.1:6379> lrange Listname1 0-1
1) "value-"
2) "value+" 3) "value" Rpoplpush from the previous list, the pop-up element is inserted into the second list headerRpoplpush listname1 listname227.0.0.1:6379> Rpoplpush listname listname1
"value--"
127.0.0.1:6379> Lrange ListName 0-1
1) "value2"
2) "value2"
3) "Value1"
127.0.0.1:6379> Lrange listname1 0-1
1) "value--"
2) "value-"
3) "value+" 4) "value" Llen Returns the length of the list127.0.0.1:6379> Llen ListName
(integer) 3
127.0.0.1:6379> llen listname1 (integer) 4

Test for Redis Operations list

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.