Lists are ordered collections of strings. Kora supports all standard Redis list operations.
LPUSH
Insert one or more values at the head of a list.
Syntax
LPUSH key value [value ...]
One or more values to push
Return value
The length of the list after the push operation
Examples
redis-cli> LPUSH mylist "world"
(integer) 1
redis-cli> LPUSH mylist "hello"
(integer) 2
redis-cli> LRANGE mylist 0 -1
1) "hello"
2) "world"
Time complexity: O(N) where N is the number of values to push
RPUSH
Insert one or more values at the tail of a list.
Syntax
RPUSH key value [value ...]
One or more values to push
Return value
The length of the list after the push operation
Examples
redis-cli> RPUSH mylist "hello"
(integer) 1
redis-cli> RPUSH mylist "world"
(integer) 2
redis-cli> LRANGE mylist 0 -1
1) "hello"
2) "world"
Time complexity: O(N) where N is the number of values to push
LPOP
Remove and return the first element of a list.
Syntax
Return value
The value of the first element, or null if the list is empty
Examples
redis-cli> RPUSH mylist "one" "two" "three"
(integer) 3
redis-cli> LPOP mylist
"one"
redis-cli> LRANGE mylist 0 -1
1) "two"
2) "three"
Time complexity: O(1)
RPOP
Remove and return the last element of a list.
Syntax
Return value
The value of the last element, or null if the list is empty
Examples
redis-cli> RPUSH mylist "one" "two" "three"
(integer) 3
redis-cli> RPOP mylist
"three"
redis-cli> LRANGE mylist 0 -1
1) "one"
2) "two"
Time complexity: O(1)
LLEN
Get the length of a list.
Syntax
Return value
The length of the list, or 0 if the key does not exist
Examples
redis-cli> RPUSH mylist "Hello" "World"
(integer) 2
redis-cli> LLEN mylist
(integer) 2
Time complexity: O(1)
LRANGE
Get a range of elements from a list.
Syntax
The start index (0-based, negative values count from the end)
The stop index (inclusive, negative values count from the end)
Return value
Array of elements in the specified range
Examples
redis-cli> RPUSH mylist "one" "two" "three" "four"
(integer) 4
redis-cli> LRANGE mylist 0 2
1) "one"
2) "two"
3) "three"
redis-cli> LRANGE mylist -3 -1
1) "two"
2) "three"
3) "four"
redis-cli> LRANGE mylist 0 -1
1) "one"
2) "two"
3) "three"
4) "four"
Time complexity: O(S+N) where S is the start offset and N is the number of elements in the range
LINDEX
Get an element from a list by its index.
Syntax
The index (0-based, negative values count from the end)
Return value
The element at the index, or null if the index is out of range
Examples
redis-cli> RPUSH mylist "one" "two" "three"
(integer) 3
redis-cli> LINDEX mylist 0
"one"
redis-cli> LINDEX mylist -1
"three"
redis-cli> LINDEX mylist 5
(nil)
Time complexity: O(N) where N is the number of elements to traverse to reach the index
LSET
Set the value of an element in a list by its index.
Syntax
The index of the element to set
Return value
OK on success, error if the index is out of range
Examples
redis-cli> RPUSH mylist "one" "two" "three"
(integer) 3
redis-cli> LSET mylist 0 "four"
OK
redis-cli> LRANGE mylist 0 -1
1) "four"
2) "two"
3) "three"
Time complexity: O(N) where N is the number of elements to traverse to reach the index
LINSERT
Insert an element before or after another element in a list.
Syntax
LINSERT key BEFORE|AFTER pivot value
Where to insert relative to the pivot
Return value
The length of the list after the insert, or -1 if the pivot was not found
Examples
redis-cli> RPUSH mylist "Hello" "World"
(integer) 2
redis-cli> LINSERT mylist BEFORE "World" "Beautiful"
(integer) 3
redis-cli> LRANGE mylist 0 -1
1) "Hello"
2) "Beautiful"
3) "World"
Time complexity: O(N) where N is the number of elements to traverse to find the pivot
LREM
Remove elements from a list.
Syntax
Number of elements to remove: positive from head, negative from tail, 0 = all occurrences
Return value
The number of removed elements
Examples
redis-cli> RPUSH mylist "hello" "hello" "foo" "hello"
(integer) 4
redis-cli> LREM mylist -2 "hello"
(integer) 2
redis-cli> LRANGE mylist 0 -1
1) "hello"
2) "foo"
Time complexity: O(N+M) where N is the length of the list and M is the number of removed elements
LTRIM
Trim a list to the specified range.
Syntax
The stop index (inclusive)
Return value
Examples
redis-cli> RPUSH mylist "one" "two" "three" "four" "five"
(integer) 5
redis-cli> LTRIM mylist 1 -1
OK
redis-cli> LRANGE mylist 0 -1
1) "two"
2) "three"
3) "four"
4) "five"
Time complexity: O(N) where N is the number of elements to be removed
LPOS
Return the index of matching elements in a list.
Syntax
LPOS key value [RANK rank] [COUNT count] [MAXLEN len]
Skip N matches before returning (can be negative to search from tail)
Return up to COUNT positions (0 = all)
Limit the search to MAXLEN elements
Return value
The position(s) of the element, or null if not found
Examples
redis-cli> RPUSH mylist "a" "b" "c" "1" "2" "3" "c" "c"
(integer) 8
redis-cli> LPOS mylist "c"
(integer) 2
redis-cli> LPOS mylist "c" RANK 2
(integer) 6
redis-cli> LPOS mylist "c" COUNT 0
1) (integer) 2
2) (integer) 6
3) (integer) 7
Time complexity: O(N) where N is the number of elements scanned
RPOPLPUSH
Remove the last element in a list, prepend it to another list and return it.
Syntax
RPOPLPUSH source destination
Return value
The element being popped and pushed, or null if source is empty
Examples
redis-cli> RPUSH mylist "one" "two" "three"
(integer) 3
redis-cli> RPOPLPUSH mylist myotherlist
"three"
redis-cli> LRANGE mylist 0 -1
1) "one"
2) "two"
redis-cli> LRANGE myotherlist 0 -1
1) "three"
Time complexity: O(1)
LMOVE
Pop an element from a list, push it to another list and return it.
Syntax
LMOVE source destination LEFT|RIGHT LEFT|RIGHT
LEFT or RIGHT - where to pop from source
LEFT or RIGHT - where to push to destination
Return value
The element being moved, or null if source is empty
Examples
redis-cli> RPUSH mylist "one" "two" "three"
(integer) 3
redis-cli> LMOVE mylist myotherlist RIGHT LEFT
"three"
redis-cli> LMOVE mylist myotherlist LEFT RIGHT
"one"
redis-cli> LRANGE mylist 0 -1
1) "two"
redis-cli> LRANGE myotherlist 0 -1
1) "three"
2) "one"
Time complexity: O(1)
Redis Compatibility
Kora implements all standard Redis list commands with identical semantics.