Redis – Lists

  • Post author:
  • Post category:Redis
  • Post comments:0 Comments

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

Maximum length of a list is 232 – 1 elements (4294967295, more than 4 billion of elements per list).

Example

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

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

Redis Lists Commands

Following table lists some basic commands related to lists.

Sr.NoCommand & Description
1BLPOP key1 [key2 ]https://adglob.in/blog/redis-list-blpop-command/
Removes and gets the first element in a list, or blocks until one is available
2BRPOP key1 [key2 ] https://adglob.in/blog/redis-list-brpop-command/
Removes and gets the last element in a list, or blocks until one is available
3BRPOPLPUSH source https://adglob.in/blog/redis-list-brpoplpush-command/
Pops a value from a list, pushes it to another list and returns it; or blocks until one is available
4LINDEX key indexhttps://adglob.in/blog/redis-list-lindex-command/
Gets an element from a list by its index
5LINSERT key BEFORE|AFTER https://adglob.in/blog/redis-list-linsert-command/
Inserts an element before or after another element in a list
6LLEN keyhttps://adglob.in/blog/redis-list-llen-command/
Gets the length of a list
7LPOP keyhttps://adglob.in/blog/redis-list-lpop-command/
Removes and gets the first element in a list
8LPUSH key value1 [value2]https://adglob.in/blog/redis-list-lpush-command/
Prepends one or multiple values to a list
9LPUSHX keyhttps://adglob.in/blog/redis-list-lpushx-command/
Prepends a value to a list, only if the list exists
10LRANGE key start stophttps://adglob.in/blog/redis-list-lrange-command/
Gets a range of elements from a list
11LREM key count valuehttps://adglob.in/blog/redis-list-lrem-command/
Removes elements from a list
12LSET key index valuehttps://adglob.in/blog/redis-list-lset-command/
Sets the value of an element in a list by its index
13LTRIM key https://adglob.in/blog/redis-list-ltrim-command/
start stopTrims a list to the specified range
14RPOP keyhttps://adglob.in/blog/redis-list-rpop-command/
Removes and gets the last element in a list
15RPOPLPUSHhttps://adglob.in/blog/redis-list-rpoplpush-command/
Removes the last element in a list, appends it to another list and returns it
16RPUSH key https://adglob.in/blog/redis-list-rpush-command/
Appends one or multiple values to a list
17RPUSHX https://adglob.in/blog/redis-list-rpushx-command/
Appends a value to a list, only if the list exists

Leave a Reply