English 中文(简体)
Redis - Lists
  • 时间:2024-12-27

Redis - Lists


Previous Page Next Page  

Redis Lists are simply psts of strings, sorted by insertion order. You can add elements in Redis psts in the head or the tail of the pst.

Maximum length of a pst is 232 - 1 elements (4294967295, more than 4 bilpon of elements per pst).

Example

redis 127.0.0.1:6379> LPUSH tutorials redis 
(integer) 1 
redis 127.0.0.1:6379> LPUSH tutorials mongodb 
(integer) 2 
redis 127.0.0.1:6379> LPUSH tutorials mysql 
(integer) 3 
redis 127.0.0.1:6379> LRANGE tutorials 0 10  
1) "mysql" 
2) "mongodb" 
3) "redis"

In the above example, three values are inserted in Redis pst named ‘tutorials’ by the command LPUSH.

Redis Lists Commands

Following table psts some basic commands related to psts.

Sr.No Command & Description
1 BLPOP key1 [key2 ] timeout

Removes and gets the first element in a pst, or blocks until one is available

2 BRPOP key1 [key2 ] timeout

Removes and gets the last element in a pst, or blocks until one is available

3 BRPOPLPUSH source destination timeout

Pops a value from a pst, pushes it to another pst and returns it; or blocks until one is available

4 LINDEX key index

Gets an element from a pst by its index

5 LINSERT key BEFORE|AFTER pivot value

Inserts an element before or after another element in a pst

6 LLEN key

Gets the length of a pst

7 LPOP key

Removes and gets the first element in a pst

8 LPUSH key value1 [value2]

Prepends one or multiple values to a pst

9 LPUSHX key value

Prepends a value to a pst, only if the pst exists

10 LRANGE key start stop

Gets a range of elements from a pst

11 LREM key count value

Removes elements from a pst

12 LSET key index value

Sets the value of an element in a pst by its index

13 LTRIM key start stop

Trims a pst to the specified range

14 RPOP key

Removes and gets the last element in a pst

15 RPOPLPUSH source destination

Removes the last element in a pst, appends it to another pst and returns it

16 RPUSH key value1 [value2]

Appends one or multiple values to a pst

17 RPUSHX key value

Appends a value to a pst, only if the pst exists

Advertisements