lpush list onelpush list twolpush list threeUse
lpush, the l here can be regarded as left, that is, inserted on the left, so the current list is like this
[three , two, one].
rpush to insert elements on the right, that is, at the end of the list.
rpush list right1 right2At this time, the list is like this
[three, two, one, right1, right2]. Use
lrange list 0 -1 to get:
range(), get the element by passing in the start and end subscripts.
lrange list 1 43. Pop removal elementSince the above can be added to the left and right, then the removal can naturally be divided into left and right. Removal operation returns the removed element. 1. lpop removes the left side
lpop list
rpop list
lindex list 1
llen list6. lrem removes specified elementsYou can specify the element to be removed, and specify the number.
lrem list 2 yi222There are 3 yi222s in the list now, and I want to remove 2 of them. 7. ltrim trimmingThrough
ltrim, only the specified part is retained, and other parts are removed, and the intercepted list changes. .
ltrim list 1 4Here the subscripts from 1 to 4 are retained, and the others are removed. 8. Combination command rpoplpush remove and addThis is a combination command, remove the last element of the list and add it to another list .
rpoplpush list list2Here
list is the original list,
list2 is the target list, and if the target list does not exist, it will be created.
exists list
lset list 1 test
linsert list before test before_testThis is the element
testBefore, insert element
before_test.
linsert list after test after_testThis is after element
test, insert element
after_test.
The above is the detailed content of What are the common operation commands of Redis basic data type List?. For more information, please follow other related articles on the PHP Chinese website!