Class DefaultRedisList<E>
java.lang.Object
java.util.AbstractCollection<E>
org.springframework.data.redis.support.collections.AbstractRedisCollection<E>
org.springframework.data.redis.support.collections.DefaultRedisList<E>
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,BlockingDeque<E>
,BlockingQueue<E>
,Deque<E>
,List<E>
,Queue<E>
,BoundKeyOperations<String>
,RedisCollection<E>
,RedisList<E>
,RedisStore
Default implementation for
RedisList
. Suitable for not just lists, but also queues (FIFO ordering) or stacks
(LIFO ordering) and deques (or double ended queues). Allows the maximum size (or the cap) to be specified to prevent
the list from over growing. Note that all write operations will execute immediately, whether a cap is specified or
not - the list will always accept new items (trimming the tail after each insert in case of capped collections).- Author:
- Costin Leau, Christoph Strobl, Mark Paluch, John Blum, Jinbeom Kim
-
Field Summary
Fields inherited from class org.springframework.data.redis.support.collections.AbstractRedisCollection
ENCODING
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultRedisList
(String key, RedisOperations<String, E> operations) Constructs a new, uncappedDefaultRedisList
instance.DefaultRedisList
(String key, RedisOperations<String, E> operations, int maxSize) Constructs a newDefaultRedisList
instance constrained to the givenmax size
.DefaultRedisList
(BoundListOperations<String, E> boundOps) Constructs a new, uncappedDefaultRedisList
instance.DefaultRedisList
(BoundListOperations<String, E> boundOps, int maxSize) Constructs a newDefaultRedisList
instance constrained to the givenmax size
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
boolean
boolean
addAll
(int index, Collection<? extends E> collection) void
void
void
clear()
int
drainTo
(Collection<? super E> collection) int
drainTo
(Collection<? super E> collection, int maxElements) element()
get
(int index) getFirst()
getLast()
getType()
Returns the associated Redis type.int
iterator()
int
lastIndexOf
(Object element) listIterator
(int index) moveFirstTo
(RedisList<E> destination, RedisListCommands.Direction destinationPosition) Atomically returns and removes the first element of the list stored at the bound key, and pushes the element at the first/last element (head/tail depending on thedestinationPosition
argument) of the list stored atdestination
.moveFirstTo
(RedisList<E> destination, RedisListCommands.Direction destinationPosition, long timeout, TimeUnit unit) Atomically returns and removes the first element of the list stored at the bound key, and pushes the element at the first/last element (head/tail depending on thedestinationPosition
argument) of the list stored atdestination
.moveLastTo
(RedisList<E> destination, RedisListCommands.Direction destinationPosition) Atomically returns and removes the last element of the list stored at the bound key, and pushes the element at the first/last element (head/tail depending on thedestinationPosition
argument) of the list stored atdestination
.moveLastTo
(RedisList<E> destination, RedisListCommands.Direction destinationPosition, long timeout, TimeUnit unit) Atomically returns and removes the last element of the list stored at the bound key, and pushes the element at the first/last element (head/tail depending on thedestinationPosition
argument) of the list stored atdestination
.boolean
boolean
boolean
offerFirst
(E element) boolean
offerFirst
(E element, long timeout, TimeUnit unit) boolean
boolean
peek()
peekLast()
poll()
pollLast()
pop()
void
void
void
void
range
(long start, long end) Get elements betweenstart
andend
from list at the bound key.int
remove()
remove
(int index) boolean
boolean
removeFirstOccurrence
(Object element) boolean
removeLastOccurrence
(Object element) void
setMaxSize
(int maxSize) Sets the maximum size of the (capped) list.int
size()
subList
(int fromIndex, int toIndex) take()
takeLast()
trim
(int start, int end) Trim list at the bound key to elements betweenstart
andend
.trim
(long start, long end) Trim list at the bound key to elements betweenstart
andend
.Methods inherited from class org.springframework.data.redis.support.collections.AbstractRedisCollection
addAll, checkResult, containsAll, equals, expire, expireAt, getExpire, getKey, getOperations, hashCode, persist, removeAll, rename, toString
Methods inherited from class java.util.AbstractCollection
contains, isEmpty, retainAll, toArray, toArray
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.concurrent.BlockingDeque
contains
Methods inherited from interface org.springframework.data.redis.core.BoundKeyOperations
expire, expire, expireAt, expireAt, getExpire, getKey, persist, rename
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.List
addAll, contains, containsAll, equals, hashCode, isEmpty, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
Methods inherited from interface org.springframework.data.redis.support.collections.RedisList
moveFirstTo, moveLastTo, reversed
Methods inherited from interface org.springframework.data.redis.support.collections.RedisStore
getOperations
-
Constructor Details
-
DefaultRedisList
Constructs a new, uncappedDefaultRedisList
instance.- Parameters:
key
- Redis key of this list.operations
-RedisOperations
used to retrieve values of the declaredtype
from this list.
-
DefaultRedisList
Constructs a newDefaultRedisList
instance constrained to the givenmax size
.- Parameters:
key
- Redis key of this list.operations
-RedisOperations
used to retrieve values of the declaredtype
from this list.maxSize
-maximum number of elements
allowed to be stored in this list.- Since:
- 2.6
-
DefaultRedisList
Constructs a new, uncappedDefaultRedisList
instance.- Parameters:
boundOps
-BoundListOperations
for the value type of this list.
-
DefaultRedisList
Constructs a newDefaultRedisList
instance constrained to the givenmax size
.- Parameters:
boundOps
-BoundListOperations
for the value type of this list.maxSize
-maximum number of elements
allowed to be stored in this list.
-
-
Method Details
-
setMaxSize
public void setMaxSize(int maxSize) Sets the maximum size of the (capped) list. A value of 0 means unlimited.- Parameters:
maxSize
- list maximum size
-
moveFirstTo
Description copied from interface:RedisList
Atomically returns and removes the first element of the list stored at the bound key, and pushes the element at the first/last element (head/tail depending on thedestinationPosition
argument) of the list stored atdestination
.- Specified by:
moveFirstTo
in interfaceRedisList<E>
- Parameters:
destination
- must not be null.destinationPosition
- must not be null.- Returns:
- See Also:
-
moveFirstTo
public E moveFirstTo(RedisList<E> destination, RedisListCommands.Direction destinationPosition, long timeout, TimeUnit unit) Description copied from interface:RedisList
Atomically returns and removes the first element of the list stored at the bound key, and pushes the element at the first/last element (head/tail depending on thedestinationPosition
argument) of the list stored atdestination
.Blocks connection until element available or
timeout
reached.- Specified by:
moveFirstTo
in interfaceRedisList<E>
- Parameters:
destination
- must not be null.destinationPosition
- must not be null.unit
- must not be null.- Returns:
- See Also:
-
moveLastTo
Description copied from interface:RedisList
Atomically returns and removes the last element of the list stored at the bound key, and pushes the element at the first/last element (head/tail depending on thedestinationPosition
argument) of the list stored atdestination
.- Specified by:
moveLastTo
in interfaceRedisList<E>
- Parameters:
destination
- must not be null.destinationPosition
- must not be null.- Returns:
- See Also:
-
moveLastTo
public E moveLastTo(RedisList<E> destination, RedisListCommands.Direction destinationPosition, long timeout, TimeUnit unit) Description copied from interface:RedisList
Atomically returns and removes the last element of the list stored at the bound key, and pushes the element at the first/last element (head/tail depending on thedestinationPosition
argument) of the list stored atdestination
.Blocks connection until element available or
timeout
reached.- Specified by:
moveLastTo
in interfaceRedisList<E>
- Parameters:
destination
- must not be null.destinationPosition
- must not be null.unit
- must not be null.- Returns:
- See Also:
-
range
Description copied from interface:RedisList
Get elements betweenstart
andend
from list at the bound key. -
trim
Description copied from interface:RedisList
Trim list at the bound key to elements betweenstart
andend
. -
trim
Description copied from interface:RedisList
Trim list at the bound key to elements betweenstart
andend
. -
iterator
-
size
public int size()- Specified by:
size
in interfaceBlockingDeque<E>
- Specified by:
size
in interfaceCollection<E>
- Specified by:
size
in interfaceDeque<E>
- Specified by:
size
in interfaceList<E>
- Specified by:
size
in classAbstractCollection<E>
-
add
- Specified by:
add
in interfaceBlockingDeque<E>
- Specified by:
add
in interfaceBlockingQueue<E>
- Specified by:
add
in interfaceCollection<E>
- Specified by:
add
in interfaceDeque<E>
- Specified by:
add
in interfaceList<E>
- Specified by:
add
in interfaceQueue<E>
- Overrides:
add
in classAbstractCollection<E>
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<E>
- Specified by:
clear
in interfaceList<E>
- Overrides:
clear
in classAbstractCollection<E>
-
remove
- Specified by:
remove
in interfaceBlockingDeque<E>
- Specified by:
remove
in interfaceBlockingQueue<E>
- Specified by:
remove
in interfaceCollection<E>
- Specified by:
remove
in interfaceDeque<E>
- Specified by:
remove
in interfaceList<E>
- Overrides:
remove
in classAbstractCollection<E>
-
add
-
addAll
-
get
-
indexOf
-
lastIndexOf
- Specified by:
lastIndexOf
in interfaceList<E>
-
listIterator
- Specified by:
listIterator
in interfaceList<E>
-
listIterator
- Specified by:
listIterator
in interfaceList<E>
-
remove
-
set
-
subList
-
element
-
offer
-
peek
-
poll
-
remove
-
addFirst
Description copied from interface:RedisList
This method is forward-compatible with Java 21 SequencedCollections.
-
addLast
Description copied from interface:RedisList
This method is forward-compatible with Java 21 SequencedCollections.
-
descendingIterator
- Specified by:
descendingIterator
in interfaceDeque<E>
-
getFirst
Description copied from interface:RedisList
This method is forward-compatible with Java 21 SequencedCollections.
-
getLast
Description copied from interface:RedisList
This method is forward-compatible with Java 21 SequencedCollections.
-
offerFirst
- Specified by:
offerFirst
in interfaceBlockingDeque<E>
- Specified by:
offerFirst
in interfaceDeque<E>
-
offerLast
-
peekFirst
-
peekLast
-
pollFirst
-
pollLast
-
pop
-
push
-
removeFirst
Description copied from interface:RedisList
This method is forward-compatible with Java 21 SequencedCollections.
- Specified by:
removeFirst
in interfaceDeque<E>
- Specified by:
removeFirst
in interfaceRedisList<E>
- Returns:
- the head of this
Deque
.
-
removeFirstOccurrence
- Specified by:
removeFirstOccurrence
in interfaceBlockingDeque<E>
- Specified by:
removeFirstOccurrence
in interfaceDeque<E>
-
removeLast
Description copied from interface:RedisList
This method is forward-compatible with Java 21 SequencedCollections.
- Specified by:
removeLast
in interfaceDeque<E>
- Specified by:
removeLast
in interfaceRedisList<E>
- Returns:
- the tail of this
Deque
.
-
removeLastOccurrence
- Specified by:
removeLastOccurrence
in interfaceBlockingDeque<E>
- Specified by:
removeLastOccurrence
in interfaceDeque<E>
-
drainTo
- Specified by:
drainTo
in interfaceBlockingQueue<E>
-
drainTo
- Specified by:
drainTo
in interfaceBlockingQueue<E>
-
offer
- Specified by:
offer
in interfaceBlockingDeque<E>
- Specified by:
offer
in interfaceBlockingQueue<E>
- Throws:
InterruptedException
-
poll
- Specified by:
poll
in interfaceBlockingDeque<E>
- Specified by:
poll
in interfaceBlockingQueue<E>
- Throws:
InterruptedException
-
put
- Specified by:
put
in interfaceBlockingDeque<E>
- Specified by:
put
in interfaceBlockingQueue<E>
- Throws:
InterruptedException
-
remainingCapacity
public int remainingCapacity()- Specified by:
remainingCapacity
in interfaceBlockingQueue<E>
-
take
- Specified by:
take
in interfaceBlockingDeque<E>
- Specified by:
take
in interfaceBlockingQueue<E>
- Throws:
InterruptedException
-
offerFirst
- Specified by:
offerFirst
in interfaceBlockingDeque<E>
-
offerLast
- Specified by:
offerLast
in interfaceBlockingDeque<E>
-
pollFirst
- Specified by:
pollFirst
in interfaceBlockingDeque<E>
- Throws:
InterruptedException
-
pollLast
- Specified by:
pollLast
in interfaceBlockingDeque<E>
-
putFirst
- Specified by:
putFirst
in interfaceBlockingDeque<E>
-
putLast
- Specified by:
putLast
in interfaceBlockingDeque<E>
- Throws:
InterruptedException
-
takeFirst
- Specified by:
takeFirst
in interfaceBlockingDeque<E>
- Throws:
InterruptedException
-
takeLast
- Specified by:
takeLast
in interfaceBlockingDeque<E>
-
getType
Description copied from interface:BoundKeyOperations
Returns the associated Redis type.- Specified by:
getType
in interfaceBoundKeyOperations<E>
- Returns:
- key type. null when used in pipeline / transaction.
-