Python redis list operation

Source: Internet
Author: User

Lpush list_name value [value ...]

Prepend one or multiple values to a list

Inserts a value from the left, the oldest inserted value at the far right

Lpushx List_name Value

Prepend a value to a list, only if the list exists

Determine if the list exists, insert a value if it exists, do not insert a value, insert only once, insert from the left

Linsert List_name before| After pivot value

Insert an element before or after another element in a list

R.linsert (' List1 ', ' before ', 6, 7)

Insert a new value before or after a value in the list, because it is calculated from the left side, so the front is the left side and the right side is behind.

Rpush list_name value [value ...]

Append one or multiple values to a list

R.rpush (' List1 ', 8, 9)

Insert a value from the right side of the list to insert multiple

Rpushx List_name Value

Append a value to a list, only if the list exists

R.rpushx (' List1 ', 9)

To determine if a list exists, insert a value from the right side of the list, insert only one at a time, and not exist to create

Lpop List_name

Remove and get the first element in a list

R.lpop (' List1 ')

Returns an element from the leftmost side of the list

Rpop Key

Remove and get the last element in a list

R.rpop (' List1 ')

Returns an element from the far right of the list

Blpop list_name1 [list_name2 ...] timeout

Remove and get the first element in a list, or block until one is available

If the list of actions does not exist, it will block

R.blpop (' List2 ')

R.blpop (["List1", "List2"])

R.blpop (["List1", "List2"], 100)

Remove the leftmost element of the queue in the list of queues, if it is empty, then block

Brpop list_name1 [list_name2 ...] timeout

Remove and get the last element in a list, or block until one is available

If the list of actions does not exist, it will block

R.brpop (' List2 ')

R.brpop (["List1", "List2"])

R.brpop (["List1", "List2"], 100)

Remove the rightmost element of the queue in the list of queues, and if it is empty, block

LSET List_name Index value

Set the value of an element in a list by its index

R.lset (' List1 ', 0, 999)

Set the queue to specify the value of the cursor

LINDEX List_name Index

Get an element from a list by its index

R.lindex (' List1 ', 1)

Gets the value of the specified underlying in the queue

Lrange list_name Start stop

Get a range of elements from a list

R.lrange (' List1 ', 0, 3)

Gets the value of the specified range in the queue

Llen List_name

Get the length of a list

R.llen (' List1 ')

Get Queue Length

Lrem List_name Value Count

Remove elements from a list

R.lrem (' List1 ', 999, 0)

Delete the specified value in the queue

List name of the Name:redis

Value: The values to remove

num:num=0 deletes all specified values from the list;

Num=2 from front to back, delete 2;

Num=-2 from the back forward, remove 2 "

LTRIM list_name Start stop

Trim a list to the specified range

R.ltrim (' List1 ', 0, 1)

Remove values from the list that are not within the index

Rpoplpush Source Destination

Remove the last element in a list, prepend it to another list and return it

R.rpoplpush (' List1 ', ' List2 ')

POPs the rightmost data from the source queue and inserts the leftmost side of the destination queue, as well as the return value

Brpoplpush Source Destination Timeout

Pop a value from a list, push it to another list and return it; or block until one is available

POPs the rightmost data from the source queue and inserts the leftmost side of the destination queue, and as a return value, no time is worth blocking

Python redis list operation

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.