public interface ListCommands
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
blmove(java.lang.String srcKey,
java.lang.String dstKey,
ListDirection from,
ListDirection to,
double timeout)
Pop an element from a list, push it to another list and return it; or block until one is available
|
java.util.List<java.lang.String> |
blmovem(java.lang.String srcKey,
java.lang.String dstKey,
ListDirection from,
ListDirection to,
double timeout)
BLMOVEM Command
The blocking variant of
lmovem(String, String, ListDirection, ListDirection). |
java.util.List<java.lang.String> |
blmovem(java.lang.String srcKey,
java.lang.String dstKey,
ListDirection from,
ListDirection to,
double timeout,
LMoveMParams params)
BLMOVEM Command
The blocking variant of
lmovem(String, String, ListDirection, ListDirection, LMoveMParams). |
KeyValue<java.lang.String,java.util.List<java.lang.String>> |
blmpop(double timeout,
ListDirection direction,
int count,
java.lang.String... keys) |
KeyValue<java.lang.String,java.util.List<java.lang.String>> |
blmpop(double timeout,
ListDirection direction,
java.lang.String... keys) |
KeyValue<java.lang.String,java.lang.String> |
blpop(double timeout,
java.lang.String... keys)
The blocking version of
lpop(String) LPOP} because it blocks the connection
when there are no elements to pop from any of the given lists. |
KeyValue<java.lang.String,java.lang.String> |
blpop(double timeout,
java.lang.String key) |
java.util.List<java.lang.String> |
blpop(int timeout,
java.lang.String... keys)
The blocking version of
lpop(String) LPOP} because it blocks the connection
when there are no elements to pop from any of the given lists. |
java.util.List<java.lang.String> |
blpop(int timeout,
java.lang.String key) |
KeyValue<java.lang.String,java.lang.String> |
brpop(double timeout,
java.lang.String... keys)
The blocking version of
rpop(String) RPOP} because it blocks the connection
when there are no elements to pop from any of the given lists. |
KeyValue<java.lang.String,java.lang.String> |
brpop(double timeout,
java.lang.String key) |
java.util.List<java.lang.String> |
brpop(int timeout,
java.lang.String... keys)
The blocking version of
rpop(String) RPOP} because it blocks the connection
when there are no elements to pop from any of the given lists. |
java.util.List<java.lang.String> |
brpop(int timeout,
java.lang.String key) |
java.lang.String |
brpoplpush(java.lang.String source,
java.lang.String destination,
int timeout)
Deprecated.
Use
blmove(String, String, ListDirection, ListDirection, double) with
ListDirection.RIGHT and ListDirection.LEFT.
Deprecated in Jedis 7.3.0. Mirrors Redis deprecation since 6.2.0. |
java.lang.String |
lindex(java.lang.String key,
long index)
Returns the element at index in the list stored at key. 0 is the first element, 1 the second
and so on.
|
long |
linsert(java.lang.String key,
ListPosition where,
java.lang.String pivot,
java.lang.String value)
Inserts element in the list stored at key either before or after the reference value pivot.
|
long |
llen(java.lang.String key)
Return the length of the list stored at the specified key.
|
java.lang.String |
lmove(java.lang.String srcKey,
java.lang.String dstKey,
ListDirection from,
ListDirection to)
Pop an element from a list, push it to another list and return it
|
java.util.List<java.lang.String> |
lmovem(java.lang.String srcKey,
java.lang.String dstKey,
ListDirection from,
ListDirection to)
LMOVEM Command
Atomically move one element from the head (LEFT) or tail (RIGHT) of the list at
srcKey, push it onto the head (LEFT) or tail (RIGHT) of the list at dstKey, and
return it wrapped in a list. |
java.util.List<java.lang.String> |
lmovem(java.lang.String srcKey,
java.lang.String dstKey,
ListDirection from,
ListDirection to,
LMoveMParams params)
LMOVEM Command
Atomically move multiple elements from the head (LEFT) or tail (RIGHT) of the list at
srcKey onto the head (LEFT) or tail (RIGHT) of the list at dstKey, and return
them in destination order. |
KeyValue<java.lang.String,java.util.List<java.lang.String>> |
lmpop(ListDirection direction,
int count,
java.lang.String... keys) |
KeyValue<java.lang.String,java.util.List<java.lang.String>> |
lmpop(ListDirection direction,
java.lang.String... keys) |
java.lang.String |
lpop(java.lang.String key)
Atomically return and remove the first (LPOP) or last (RPOP) element of the list.
|
java.util.List<java.lang.String> |
lpop(java.lang.String key,
int count)
Atomically return and remove the first (LPOP) or last (RPOP) element of the list.
|
java.lang.Long |
lpos(java.lang.String key,
java.lang.String element)
Returns the index of the first matching element inside a redis list.
|
java.lang.Long |
lpos(java.lang.String key,
java.lang.String element,
LPosParams params)
In case there are multiple matches Rank option specifies the "rank" of the element to return.
|
java.util.List<java.lang.Long> |
lpos(java.lang.String key,
java.lang.String element,
LPosParams params,
long count)
Returns the index of matching elements inside a Redis list.
|
long |
lpush(java.lang.String key,
java.lang.String... strings)
Add the string value to the head (LPUSH) or tail (RPUSH) of the list stored at key.
|
long |
lpushx(java.lang.String key,
java.lang.String... strings)
Inserts specified values at the head of the list stored at key.
|
java.util.List<java.lang.String> |
lrange(java.lang.String key,
long start,
long stop)
Return the specified elements of the list stored at the specified key.
|
long |
lrem(java.lang.String key,
long count,
java.lang.String value)
Remove the first count occurrences of the value element from the list.
|
java.lang.String |
lset(java.lang.String key,
long index,
java.lang.String value)
Set a new value as the element at index position of the List at key.
|
java.lang.String |
ltrim(java.lang.String key,
long start,
long stop)
Trim an existing list so that it will contain only the specified range of elements specified.
|
java.lang.String |
rpop(java.lang.String key)
Atomically return and remove the first (LPOP) or last (RPOP) element of the list.
|
java.util.List<java.lang.String> |
rpop(java.lang.String key,
int count)
Atomically return and remove the first (LPOP) or last (RPOP) element of the list.
|
java.lang.String |
rpoplpush(java.lang.String srckey,
java.lang.String dstkey)
Deprecated.
Use
lmove(String, String, ListDirection, ListDirection) with
ListDirection.RIGHT and ListDirection.LEFT.
Deprecated in Jedis 7.3.0. Mirrors Redis deprecation since 6.2.0. |
long |
rpush(java.lang.String key,
java.lang.String... strings)
Add the string value to the head (LPUSH) or tail (RPUSH) of the list stored at key.
|
long |
rpushx(java.lang.String key,
java.lang.String... strings)
Inserts specified values at the tail of the list stored at key.
|
long rpush(java.lang.String key,
java.lang.String... strings)
Time complexity: O(1)
key - strings - data to pushlong lpush(java.lang.String key,
java.lang.String... strings)
Time complexity: O(1)
key - strings - data to pushlong llen(java.lang.String key)
Time complexity: O(1)
key - java.util.List<java.lang.String> lrange(java.lang.String key,
long start,
long stop)
For example LRANGE foobar 0 2 will return the first three elements of the list.
start and end can also be negative numbers indicating offsets from the end of the list. For example -1 is the last element of the list, -2 the penultimate element and so on.
Consistency with range functions in various programming languages
Note that if you have a list of numbers from 0 to 100, LRANGE 0 10 will return 11 elements, that is, rightmost item is included. This may or may not be consistent with behavior of range-related functions in your programming language of choice (think Ruby's Range.new, Array#slice or Python's range() function).
LRANGE behavior is consistent with one of Tcl.
Out-of-range indexes
Indexes out of range will not produce an error: if start is over the end of the list, or start > end, an empty list is returned. If end is over the end of the list Redis will threat it just like the last element of the list.
Time complexity: O(start+n) (with n being the length of the range and start being the start offset)
key - start - stop - java.lang.String ltrim(java.lang.String key,
long start,
long stop)
For example LTRIM foobar 0 2 will modify the list stored at foobar key so that only the first three elements of the list will remain.
start and end can also be negative numbers indicating offsets from the end of the list. For example -1 is the last element of the list, -2 the penultimate element and so on.
Indexes out of range will not produce an error: if start is over the end of the list, or start > end, an empty list is left as value. If end over the end of the list Redis will threat it just like the last element of the list.
Hint: the obvious use of LTRIM is together with LPUSH/RPUSH. For example:
lpush("mylist", "someelement"); ltrim("mylist", 0, 99); *
The above two commands will push elements in the list taking care that the list will not grow without limits. This is very useful when using Redis to store logs for example. It is important to note that when used in this way LTRIM is an O(1) operation because in the average case just one element is removed from the tail of the list.
Time complexity: O(n) (with n being len of list - len of range)
key - start - stop - java.lang.String lindex(java.lang.String key,
long index)
If the value stored at key is not of list type an error is returned. If the index is out of range a 'nil' reply is returned.
Note that even if the average time complexity is O(n) asking for the first or the last element of the list is O(1).
Time complexity: O(n) (with n being the length of the list)
key - index - java.lang.String lset(java.lang.String key,
long index,
java.lang.String value)
Out of range indexes will generate an error.
Similarly to other list commands accepting indexes, the index can be negative to access elements starting from the end of the list. So -1 is the last element, -2 is the penultimate, and so forth.
Time Complexity O(N) when N being the length of the list. For the first or last elements of the list is O(1)
key - index - value - long lrem(java.lang.String key,
long count,
java.lang.String value)
Time complexity: O(N) (with N being the length of the list)
key - count - value - java.lang.String lpop(java.lang.String key)
If the key does not exist or the list is already empty the special value 'nil' is returned.
key - java.util.List<java.lang.String> lpop(java.lang.String key,
int count)
key - count - java.lang.Long lpos(java.lang.String key,
java.lang.String element)
Time complexity: O(N) where N is the number of elements in the list
key - element - java.lang.Long lpos(java.lang.String key,
java.lang.String element,
LPosParams params)
Maxlen option compares the element provided only with a given maximum number of list items. A value of 1000 will make sure that the command performs only 1000 comparisons. The comparison is made for the first part or the last part depending on the fact we use a positive or negative rank. Following is how we could use the Maxlen option lpos("foo", "b", LPosParams.lPosParams().rank(1).maxlen(2)).
key - element - params - LPosParamsjava.util.List<java.lang.Long> lpos(java.lang.String key,
java.lang.String element,
LPosParams params,
long count)
Time complexity: O(N) where N is the number of elements in the list
key - element - params - LPosParamscount - java.lang.String rpop(java.lang.String key)
key - java.util.List<java.lang.String> rpop(java.lang.String key,
int count)
key - count - return up to count elementslong linsert(java.lang.String key,
ListPosition where,
java.lang.String pivot,
java.lang.String value)
When key does not exist, it is considered an empty list and no operation is performed.
key - where - can be BEFORE or AFTERpivot - reference valuevalue - the valuelong lpushx(java.lang.String key,
java.lang.String... strings)
LPUSH, no operation will be performed when key
does not yet exist.key - strings - the strings to pushlong rpushx(java.lang.String key,
java.lang.String... strings)
RPUSH, no operation will be performed when key
does not yet exist.key - strings - the strings to pushjava.util.List<java.lang.String> blpop(int timeout,
java.lang.String... keys)
lpop(String) LPOP} because it blocks the connection
when there are no elements to pop from any of the given lists. An element is popped from the head of
the first list that is non-empty, with the given keys being checked in the order that they are given.timeout - the timeout argument is interpreted as a double value specifying the maximum number of
seconds to block. A timeout of zero can be used to block indefinitely.keys - java.util.List<java.lang.String> blpop(int timeout,
java.lang.String key)
blpop(int, String...)KeyValue<java.lang.String,java.lang.String> blpop(double timeout, java.lang.String... keys)
lpop(String) LPOP} because it blocks the connection
when there are no elements to pop from any of the given lists. An element is popped from the head of
the first list that is non-empty, with the given keys being checked in the order that they are given.timeout - the timeout argument is interpreted as a double value specifying the maximum number of
seconds to block. A timeout of zero can be used to block indefinitely.keys - KeyValue<java.lang.String,java.lang.String> blpop(double timeout, java.lang.String key)
blpop(double, String...)java.util.List<java.lang.String> brpop(int timeout,
java.lang.String... keys)
rpop(String) RPOP} because it blocks the connection
when there are no elements to pop from any of the given lists. An element is popped from the tail of
the first list that is non-empty, with the given keys being checked in the order that they are given.timeout - the timeout argument is interpreted as a double value specifying the maximum number of
seconds to block. A timeout of zero can be used to block indefinitely.keys - java.util.List<java.lang.String> brpop(int timeout,
java.lang.String key)
brpop(int, String...)KeyValue<java.lang.String,java.lang.String> brpop(double timeout, java.lang.String... keys)
rpop(String) RPOP} because it blocks the connection
when there are no elements to pop from any of the given lists. An element is popped from the tail of
the first list that is non-empty, with the given keys being checked in the order that they are given.timeout - the timeout argument is interpreted as a double value specifying the maximum number of
seconds to block. A timeout of zero can be used to block indefinitely.keys - KeyValue<java.lang.String,java.lang.String> brpop(double timeout, java.lang.String key)
brpop(double, String...)@Deprecated
java.lang.String rpoplpush(java.lang.String srckey,
java.lang.String dstkey)
lmove(String, String, ListDirection, ListDirection) with
ListDirection.RIGHT and ListDirection.LEFT.
Deprecated in Jedis 7.3.0. Mirrors Redis deprecation since 6.2.0.If the key does not exist or the list is already empty the special value 'nil' is returned. If the srckey and dstkey are the same the operation is equivalent to removing the last element from the list and pushing it as first element of the list, so it's a "list rotation" command.
Time complexity: O(1)
srckey - dstkey - @Deprecated
java.lang.String brpoplpush(java.lang.String source,
java.lang.String destination,
int timeout)
blmove(String, String, ListDirection, ListDirection, double) with
ListDirection.RIGHT and ListDirection.LEFT.
Deprecated in Jedis 7.3.0. Mirrors Redis deprecation since 6.2.0.rpoplpush(String, String). When source is
empty, Redis will block the connection until another client pushes to it or until timeout is
reached. A timeout of zero can be used to block indefinitely.
Time complexity: O(1)
source - destination - timeout - the timeout argument is interpreted as a double value specifying the maximum number of
seconds to block. A timeout of zero can be used to block indefinitely.java.lang.String lmove(java.lang.String srcKey,
java.lang.String dstKey,
ListDirection from,
ListDirection to)
srcKey - dstKey - from - can be LEFT or RIGHTto - can be LEFT or RIGHTjava.lang.String blmove(java.lang.String srcKey,
java.lang.String dstKey,
ListDirection from,
ListDirection to,
double timeout)
srcKey - dstKey - from - can be LEFT or RIGHTto - can be LEFT or RIGHTtimeout - the timeout argument is interpreted as a double value specifying the maximum number of
seconds to block. A timeout of zero can be used to block indefinitely.java.util.List<java.lang.String> lmovem(java.lang.String srcKey,
java.lang.String dstKey,
ListDirection from,
ListDirection to)
srcKey, push it onto the head (LEFT) or tail (RIGHT) of the list at dstKey, and
return it wrapped in a list. Without a count block this is equivalent to
lmove(String, String, ListDirection, ListDirection).
Time complexity: O(1)
srcKey - the source listdstKey - the destination listfrom - where to pop from the source, LEFT or RIGHTto - where to push to the destination, LEFT or RIGHTnull if the source list does not existjava.util.List<java.lang.String> lmovem(java.lang.String srcKey,
java.lang.String dstKey,
ListDirection from,
ListDirection to,
LMoveMParams params)
srcKey onto the head (LEFT) or tail (RIGHT) of the list at dstKey, and return
them in destination order. The params select how many elements to move
(COUNT: up to; EXACTLY: exactly or nothing) and their ordering (OBO:
one by one; BULK: in bulk).
Time complexity: O(N) where N is the number of elements moved.
srcKey - the source listdstKey - the destination listfrom - where to pop from the source, LEFT or RIGHTto - where to push to the destination, LEFT or RIGHTparams - the count and ordering of the movenull if the source list does not
exist or, with EXACTLY, holds fewer than the requested number of elementsjava.util.List<java.lang.String> blmovem(java.lang.String srcKey,
java.lang.String dstKey,
ListDirection from,
ListDirection to,
double timeout)
lmovem(String, String, ListDirection, ListDirection). When
the source list is empty, Redis blocks the connection until another client pushes to it or
until timeout is reached.
Time complexity: O(1)
srcKey - the source listdstKey - the destination listfrom - where to pop from the source, LEFT or RIGHTto - where to push to the destination, LEFT or RIGHTtimeout - the maximum number of seconds to block, interpreted as a double. A timeout of
zero blocks indefinitely.null on timeoutjava.util.List<java.lang.String> blmovem(java.lang.String srcKey,
java.lang.String dstKey,
ListDirection from,
ListDirection to,
double timeout,
LMoveMParams params)
lmovem(String, String, ListDirection, ListDirection, LMoveMParams). With a
COUNT selector it blocks only while the source list is empty; with an EXACTLY
selector it blocks until the source list holds enough elements, or until timeout is
reached.
Time complexity: O(N) where N is the number of elements moved.
srcKey - the source listdstKey - the destination listfrom - where to pop from the source, LEFT or RIGHTto - where to push to the destination, LEFT or RIGHTtimeout - the maximum number of seconds to block, interpreted as a double. A timeout of
zero blocks indefinitely.params - the count and ordering of the movenull on timeoutKeyValue<java.lang.String,java.util.List<java.lang.String>> lmpop(ListDirection direction, java.lang.String... keys)
KeyValue<java.lang.String,java.util.List<java.lang.String>> lmpop(ListDirection direction, int count, java.lang.String... keys)
KeyValue<java.lang.String,java.util.List<java.lang.String>> blmpop(double timeout, ListDirection direction, java.lang.String... keys)
KeyValue<java.lang.String,java.util.List<java.lang.String>> blmpop(double timeout, ListDirection direction, int count, java.lang.String... keys)
Copyright © 2026. All rights reserved.