Redis Lists

Redis lists can be defined as a list of strings, sorted by insertion order. You can add elements in Redis lists in the head or the tail of the list.

A list can contain more than 4 billion elements.

Example

Redis Lists 1

Redis Lists Commands

IndexCommandDescription
1BLPOP key1 [key2 ] timeoutIt is used to remove and get the first element in a list, or blocks until one is available.
2BRPOP key1 [key2 ] timeoutIt is used to remove and get the last element in a list, or blocks until one is available.
3BRPOPLPUSH source destination timeoutIt is used to pop a value from a list, pushes it to another list and returns it; or blocks until one is available.
4LINDEX key indexIt is used to get an element from a list by its index.
5LINSERT key before|after pivot valueIt is used to insert an element before or after another element in a list.
6LLEN keyIt is used to get the length of a list.
7LPOP keyIt is used to remove and get the first element in a list.
8LPUSH key value1 [value2]It is used to prepend one or multiple values to a list.
9LPUSHX key valueIt is used to prepend a value to a list, only if the list exists.
10LRANGE key start stopIt is used to get a range of elements from a list.
11LREM key count valueIt is used to remove elements from a list.
12LSET key index valueIt is used to set the value of an element in a list by its index.
13LTRIM key start stopIt is used to trim a list to the specified range.
14RPOP keyIt is used to remove and get the last element in a list.
15RPOPLPUSH source destinationIt is used to remove the last element in a list, append it to another list and returns it.
16RPUSH key value1 [value2]It is used to append one or multiple values to a list.
17RPUSHX key valueIt is used to append a value to a list, only if the list exists.

Next TopicRedis Sets




Latest Courses