Common usage of Redis list (List)

Redis lists are simple lists of strings, sorted by insertion order. You can add an element to the head (left) or tail (right)
of a list. A list can contain up to 2^32 - 1 elements (4294967295, over 4 billion elements per list).


1, lpush list value, inserted into the list, (in the lpush set, the value can be repeated, the return value is: the size of the list)




2, the LRANGE list startindex endindex command, traverse the value from the start index to the end index




3 LINDEX key index
through the index Get the element in the list (if it does not exist, return nil)







4 LINSERT key BEFORE|AFTER pivot value
Insert the element before or after the element of the list (if there are two identical values. According to the latter insertion)








5 LLEN key
Get the length of the list






6 LPOP key
moves out and gets the first element of the list







7
LPUSH key value1 [value2]
inserts one or more values ​​into the head of the list







9 LPUSH key value
inserts one or more values ​​into the head of an existing list







10 LRANGE key start stop
get the elements in the specified range of the list (0 -1 means get all the values)



11 LREM key count value
Remove list elements (count represents the number, if there are count values, delete them all, if not, return 0)






12 LSET key index value
Set the value of list elements by index (index starts from 0, if successful, return ok )





13 LTRIM key start stop
Trim a list (trim), that is, let the list retain only the elements within the specified range, and the elements not within the specified range will be deleted.





14 RPOP key
removes and gets the last element of the list





16 RPUSH key value1 [value2]
adds one or more values ​​to the list

17 RPUSHX key value adds a value
to an existing list (the list will be automatically created if it does not exist)






Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326441191&siteId=291194637