Interface RedisListCommands
- All Known Subinterfaces:
DefaultedRedisClusterConnection
,DefaultedRedisConnection
,RedisClusterConnection
,RedisCommands
,RedisConnection
,RedisConnectionUtils.RedisConnectionProxy
,StringRedisConnection
- All Known Implementing Classes:
AbstractRedisConnection
,DefaultStringRedisConnection
,JedisClusterConnection
,JedisConnection
,LettuceClusterConnection
,LettuceConnection
public interface RedisListCommands
List-specific commands supported by Redis.
- Author:
- Costin Leau, Christoph Strobl, Mark Paluch, dengliming
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic enum
List move direction.static enum
List insertion position. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
bLMove
(byte[] sourceKey, byte[] destinationKey, RedisListCommands.Direction from, RedisListCommands.Direction to, double timeout) Atomically returns and removes the first/last element (head/tail depending on thefrom
argument) of the list stored atsourceKey
, and pushes the element at the first/last element (head/tail depending on theto
argument) of the list stored atdestinationKey
.List<byte[]>
bLPop
(int timeout, byte[]... keys) Removes and returns first element from lists stored atkeys
.List<byte[]>
bRPop
(int timeout, byte[]... keys) Removes and returns last element from lists stored atkeys
.byte[]
bRPopLPush
(int timeout, byte[] srcKey, byte[] dstKey) Remove the last element from list atsrcKey
, append it todstKey
and return its value.byte[]
lIndex
(byte[] key, long index) Get element atindex
form list atkey
.lInsert
(byte[] key, RedisListCommands.Position where, byte[] pivot, byte[] value) Insertvalue
RedisListCommands.Position.BEFORE
orRedisListCommands.Position.AFTER
existingpivot
forkey
.lLen
(byte[] key) Get the size of list stored atkey
.byte[]
lMove
(byte[] sourceKey, byte[] destinationKey, RedisListCommands.Direction from, RedisListCommands.Direction to) Atomically returns and removes the first/last element (head/tail depending on thefrom
argument) of the list stored atsourceKey
, and pushes the element at the first/last element (head/tail depending on theto
argument) of the list stored atdestinationKey
.byte[]
lPop
(byte[] key) Removes and returns first element in list stored atkey
.List<byte[]>
lPop
(byte[] key, long count) Removes and returns first elements in list stored atkey
.default Long
lPos
(byte[] key, byte[] element) Returns the index of matching elements inside the list stored at given key.Returns the index of matching elements inside the list stored at given key.lPush
(byte[] key, byte[]... values) Prependvalues
tokey
.lPushX
(byte[] key, byte[] value) Prependvalues
tokey
only if the list exists.List<byte[]>
lRange
(byte[] key, long start, long end) Get elements betweenstart
andend
from list atkey
.lRem
(byte[] key, long count, byte[] value) Removes the firstcount
occurrences ofvalue
from the list stored atkey
.void
lSet
(byte[] key, long index, byte[] value) Set thevalue
list element atindex
.void
lTrim
(byte[] key, long start, long end) Trim list atkey
to elements betweenstart
andend
.byte[]
rPop
(byte[] key) Removes and returns last element in list stored atkey
.List<byte[]>
rPop
(byte[] key, long count) Removes and returns last elements in list stored atkey
.byte[]
rPopLPush
(byte[] srcKey, byte[] dstKey) Remove the last element from list atsrcKey
, append it todstKey
and return its value.rPush
(byte[] key, byte[]... values) Appendvalues
tokey
.rPushX
(byte[] key, byte[] value) Appendvalues
tokey
only if the list exists.
-
Method Details
-
rPush
Appendvalues
tokey
.- Parameters:
key
- must not be null.values
- must not be empty.- Returns:
- null when used in pipeline / transaction.
- See Also:
-
lPos
Returns the index of matching elements inside the list stored at given key.
Requires Redis 6.0.6 or newer.- Parameters:
key
- must not be null.element
- must not be null.- Returns:
- null when used in pipeline / transaction.
- Since:
- 2.4
- See Also:
-
lPos
@Nullable List<Long> lPos(byte[] key, byte[] element, @Nullable Integer rank, @Nullable Integer count) Returns the index of matching elements inside the list stored at given key.
Requires Redis 6.0.6 or newer.- Parameters:
key
- must not be null.element
- must not be null.rank
- specifies the "rank" of the first element to return, in case there are multiple matches. A rank of 1 means to return the first match, 2 to return the second match, and so forth.count
- number of matches to return.- Returns:
- null when used in pipeline / transaction.
- Since:
- 2.4
- See Also:
-
lPush
Prependvalues
tokey
.- Parameters:
key
- must not be null.values
- must not be empty.- Returns:
- null when used in pipeline / transaction.
- See Also:
-
rPushX
Appendvalues
tokey
only if the list exists.- Parameters:
key
- must not be null.value
- must not be null.- Returns:
- null when used in pipeline / transaction.
- See Also:
-
lPushX
Prependvalues
tokey
only if the list exists.- Parameters:
key
- must not be null.value
- must not be null.- Returns:
- null when used in pipeline / transaction.
- See Also:
-
lLen
Get the size of list stored atkey
.- Parameters:
key
- must not be null.- Returns:
- null when used in pipeline / transaction.
- See Also:
-
lRange
Get elements betweenstart
andend
from list atkey
.- Parameters:
key
- must not be null.start
-end
-- Returns:
- empty
List
if key does not exists or range does not contain values. null when used in pipeline / transaction. - See Also:
-
lTrim
void lTrim(byte[] key, long start, long end) Trim list atkey
to elements betweenstart
andend
.- Parameters:
key
- must not be null.start
-end
-- See Also:
-
lIndex
@Nullable byte[] lIndex(byte[] key, long index) Get element atindex
form list atkey
.- Parameters:
key
- must not be null.index
- zero based index value. Use negative number to designate elements starting at the tail.- Returns:
- null when index is out of range or when used in pipeline / transaction.
- See Also:
-
lInsert
Insertvalue
RedisListCommands.Position.BEFORE
orRedisListCommands.Position.AFTER
existingpivot
forkey
.- Parameters:
key
- must not be null.where
- must not be null.pivot
- must not be null.value
- must not be null.- Returns:
- null when used in pipeline / transaction.
- See Also:
-
lMove
@Nullable byte[] lMove(byte[] sourceKey, byte[] destinationKey, RedisListCommands.Direction from, RedisListCommands.Direction to) Atomically returns and removes the first/last element (head/tail depending on thefrom
argument) of the list stored atsourceKey
, and pushes the element at the first/last element (head/tail depending on theto
argument) of the list stored atdestinationKey
.- Parameters:
sourceKey
- must not be null.destinationKey
- must not be null.from
- must not be null.to
- must not be null.- Returns:
- null when used in pipeline / transaction.
- Since:
- 2.6
- See Also:
-
bLMove
@Nullable byte[] bLMove(byte[] sourceKey, byte[] destinationKey, RedisListCommands.Direction from, RedisListCommands.Direction to, double timeout) Atomically returns and removes the first/last element (head/tail depending on thefrom
argument) of the list stored atsourceKey
, and pushes the element at the first/last element (head/tail depending on theto
argument) of the list stored atdestinationKey
.Blocks connection until element available or
timeout
reached.- Parameters:
sourceKey
- must not be null.destinationKey
- must not be null.from
- must not be null.to
- must not be null.timeout
-- Returns:
- null when used in pipeline / transaction.
- Since:
- 2.6
- See Also:
-
lSet
void lSet(byte[] key, long index, byte[] value) Set thevalue
list element atindex
.- Parameters:
key
- must not be null.index
-value
-- See Also:
-
lRem
Removes the firstcount
occurrences ofvalue
from the list stored atkey
.- Parameters:
key
- must not be null.count
-value
-- Returns:
- null when used in pipeline / transaction.
- See Also:
-
lPop
@Nullable byte[] lPop(byte[] key) Removes and returns first element in list stored atkey
.- Parameters:
key
- must not be null.- Returns:
- null when key does not exist or used in pipeline / transaction.
- See Also:
-
lPop
Removes and returns first elements in list stored atkey
.- Parameters:
key
- must not be null.count
-- Returns:
- null when key does not exist or used in pipeline / transaction.
- Since:
- 2.6
- See Also:
-
rPop
@Nullable byte[] rPop(byte[] key) Removes and returns last element in list stored atkey
.- Parameters:
key
- must not be null.- Returns:
- null when key does not exist or used in pipeline / transaction.
- See Also:
-
rPop
Removes and returns last elements in list stored atkey
.- Parameters:
key
- must not be null.count
-- Returns:
- null when key does not exist or used in pipeline / transaction.
- Since:
- 2.6
- See Also:
-
bLPop
Removes and returns first element from lists stored atkeys
.
Blocks connection until element available ortimeout
reached.- Parameters:
timeout
- seconds to block.keys
- must not be null.- Returns:
- empty
List
when no element could be popped and the timeout was reached. null when used in pipeline / transaction. - See Also:
-
bRPop
Removes and returns last element from lists stored atkeys
.
Blocks connection until element available ortimeout
reached.- Parameters:
timeout
- seconds to block.keys
- must not be null.- Returns:
- empty
List
when no element could be popped and the timeout was reached. null when used in pipeline / transaction. - See Also:
-
rPopLPush
@Nullable byte[] rPopLPush(byte[] srcKey, byte[] dstKey) Remove the last element from list atsrcKey
, append it todstKey
and return its value.- Parameters:
srcKey
- must not be null.dstKey
- must not be null.- Returns:
- can be null.
- See Also:
-
bRPopLPush
@Nullable byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) Remove the last element from list atsrcKey
, append it todstKey
and return its value.
Blocks connection until element available ortimeout
reached.- Parameters:
timeout
- seconds to block.srcKey
- must not be null.dstKey
- must not be null.- Returns:
- can be null.
- See Also:
-