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 AbstractRedisCollection
ENCODING -
Constructor Summary
ConstructorsConstructorDescriptionDefaultRedisList(String key, RedisOperations<String, E> operations) Constructs a new, uncappedDefaultRedisListinstance.DefaultRedisList(String key, RedisOperations<String, E> operations, int maxSize) Constructs a newDefaultRedisListinstance constrained to the givenmax size.DefaultRedisList(BoundListOperations<String, E> boundOps) Constructs a new, uncappedDefaultRedisListinstance.DefaultRedisList(BoundListOperations<String, E> boundOps, int maxSize) Constructs a newDefaultRedisListinstance constrained to the givenmax size. -
Method Summary
Modifier and TypeMethodDescriptionvoidbooleanbooleanaddAll(int index, Collection<? extends E> collection) voidvoidvoidclear()intdrainTo(Collection<? super E> collection) intdrainTo(Collection<? super E> collection, int maxElements) element()get(int index) getFirst()getLast()getType()Returns the associated Redis type.intiterator()intlastIndexOf(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 thedestinationPositionargument) 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 thedestinationPositionargument) 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 thedestinationPositionargument) 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 thedestinationPositionargument) of the list stored atdestination.booleanbooleanbooleanofferFirst(E element) booleanofferFirst(E element, long timeout, TimeUnit unit) booleanboolean@Nullable Epeek()@Nullable E@Nullable EpeekLast()@Nullable Epoll()@Nullable E@Nullable E@Nullable E@Nullable EpollLast()@Nullable Epop()voidvoidvoidvoidrange(long start, long end) Get elements betweenstartandendfrom list at the bound key.intremove()remove(int index) booleanbooleanremoveFirstOccurrence(Object element) booleanremoveLastOccurrence(Object element) voidsetMaxSize(int maxSize) Sets the maximum size of the (capped) list.intsize()subList(int fromIndex, int toIndex) @Nullable Etake()@Nullable E@Nullable EtakeLast()trim(int start, int end) Trim list at the bound key to elements betweenstartandend.trim(long start, long end) Trim list at the bound key to elements betweenstartandend.Methods inherited from class AbstractRedisCollection
addAll, checkResult, containsAll, equals, expire, expireAt, getExpire, getKey, getOperations, hashCode, persist, removeAll, rename, toStringMethods inherited from interface BlockingDeque
containsMethods inherited from interface BoundKeyOperations
expiration, expire, expire, expireAt, expireAt, getExpire, getKey, persist, renameMethods inherited from interface Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface List
addAll, contains, containsAll, equals, hashCode, isEmpty, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArrayMethods inherited from interface RedisList
moveFirstTo, moveLastTo, reversedMethods inherited from interface RedisStore
getOperations
-
Constructor Details
-
DefaultRedisList
Constructs a new, uncappedDefaultRedisListinstance.- Parameters:
key- Redis key of this list.operations-RedisOperationsused to retrieve values of the declaredtypefrom this list.
-
DefaultRedisList
Constructs a newDefaultRedisListinstance constrained to the givenmax size.- Parameters:
key- Redis key of this list.operations-RedisOperationsused to retrieve values of the declaredtypefrom this list.maxSize-maximum number of elementsallowed to be stored in this list.- Since:
- 2.6
-
DefaultRedisList
Constructs a new, uncappedDefaultRedisListinstance.- Parameters:
boundOps-BoundListOperationsfor the value type of this list.
-
DefaultRedisList
Constructs a newDefaultRedisListinstance constrained to the givenmax size.- Parameters:
boundOps-BoundListOperationsfor the value type of this list.maxSize-maximum number of elementsallowed 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:RedisListAtomically 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 thedestinationPositionargument) of the list stored atdestination.- Specified by:
moveFirstToin 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:RedisListAtomically 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 thedestinationPositionargument) of the list stored atdestination.Blocks connection until element available or
timeoutreached.- Specified by:
moveFirstToin interfaceRedisList<E>- Parameters:
destination- must not be null.destinationPosition- must not be null.timeout-unit- must not be null.- Returns:
- See Also:
-
moveLastTo
Description copied from interface:RedisListAtomically 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 thedestinationPositionargument) of the list stored atdestination.- Specified by:
moveLastToin 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:RedisListAtomically 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 thedestinationPositionargument) of the list stored atdestination.Blocks connection until element available or
timeoutreached.- Specified by:
moveLastToin interfaceRedisList<E>- Parameters:
destination- must not be null.destinationPosition- must not be null.timeout-unit- must not be null.- Returns:
- See Also:
-
range
-
trim
-
trim
-
iterator
-
size
public int size()- Specified by:
sizein interfaceBlockingDeque<E>- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceDeque<E>- Specified by:
sizein interfaceList<E>- Specified by:
sizein classAbstractCollection<E>
-
add
- Specified by:
addin interfaceBlockingDeque<E>- Specified by:
addin interfaceBlockingQueue<E>- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceDeque<E>- Specified by:
addin interfaceList<E>- Specified by:
addin interfaceQueue<E>- Overrides:
addin classAbstractCollection<E>
-
clear
public void clear()- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceList<E>- Overrides:
clearin classAbstractCollection<E>
-
remove
- Specified by:
removein interfaceBlockingDeque<E>- Specified by:
removein interfaceBlockingQueue<E>- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceDeque<E>- Specified by:
removein interfaceList<E>- Overrides:
removein classAbstractCollection<E>
-
add
-
addAll
-
get
-
indexOf
-
lastIndexOf
- Specified by:
lastIndexOfin interfaceList<E>
-
listIterator
- Specified by:
listIteratorin interfaceList<E>
-
listIterator
- Specified by:
listIteratorin interfaceList<E>
-
remove
-
set
-
subList
-
element
-
offer
-
peek
-
poll
-
remove
-
addFirst
Description copied from interface:RedisListThis method is forward-compatible with Java 21 SequencedCollections.
-
addLast
Description copied from interface:RedisListThis method is forward-compatible with Java 21 SequencedCollections.
-
descendingIterator
- Specified by:
descendingIteratorin interfaceDeque<E>
-
getFirst
-
getLast
-
offerFirst
- Specified by:
offerFirstin interfaceBlockingDeque<E>- Specified by:
offerFirstin interfaceDeque<E>
-
offerLast
-
peekFirst
-
peekLast
-
pollFirst
-
pollLast
-
pop
-
push
-
removeFirst
Description copied from interface:RedisListThis method is forward-compatible with Java 21 SequencedCollections.
- Specified by:
removeFirstin interfaceDeque<E>- Specified by:
removeFirstin interfaceRedisList<E>- Returns:
- the head of this
Deque.
-
removeFirstOccurrence
- Specified by:
removeFirstOccurrencein interfaceBlockingDeque<E>- Specified by:
removeFirstOccurrencein interfaceDeque<E>
-
removeLast
Description copied from interface:RedisListThis method is forward-compatible with Java 21 SequencedCollections.
- Specified by:
removeLastin interfaceDeque<E>- Specified by:
removeLastin interfaceRedisList<E>- Returns:
- the tail of this
Deque.
-
removeLastOccurrence
- Specified by:
removeLastOccurrencein interfaceBlockingDeque<E>- Specified by:
removeLastOccurrencein interfaceDeque<E>
-
drainTo
- Specified by:
drainToin interfaceBlockingQueue<E>
-
drainTo
- Specified by:
drainToin interfaceBlockingQueue<E>
-
offer
- Specified by:
offerin interfaceBlockingDeque<E>- Specified by:
offerin interfaceBlockingQueue<E>- Throws:
InterruptedException
-
poll
- Specified by:
pollin interfaceBlockingDeque<E>- Specified by:
pollin interfaceBlockingQueue<E>- Throws:
InterruptedException
-
put
- Specified by:
putin interfaceBlockingDeque<E>- Specified by:
putin interfaceBlockingQueue<E>- Throws:
InterruptedException
-
remainingCapacity
public int remainingCapacity()- Specified by:
remainingCapacityin interfaceBlockingQueue<E>
-
take
- Specified by:
takein interfaceBlockingDeque<E>- Specified by:
takein interfaceBlockingQueue<E>- Throws:
InterruptedException
-
offerFirst
- Specified by:
offerFirstin interfaceBlockingDeque<E>
-
offerLast
- Specified by:
offerLastin interfaceBlockingDeque<E>
-
pollFirst
- Specified by:
pollFirstin interfaceBlockingDeque<E>- Throws:
InterruptedException
-
pollLast
- Specified by:
pollLastin interfaceBlockingDeque<E>
-
putFirst
- Specified by:
putFirstin interfaceBlockingDeque<E>
-
putLast
- Specified by:
putLastin interfaceBlockingDeque<E>- Throws:
InterruptedException
-
takeFirst
- Specified by:
takeFirstin interfaceBlockingDeque<E>- Throws:
InterruptedException
-
takeLast
- Specified by:
takeLastin interfaceBlockingDeque<E>
-
getType
Description copied from interface:BoundKeyOperationsReturns the associated Redis type.- Specified by:
getTypein interfaceBoundKeyOperations<E>- Returns:
- key type. null when used in pipeline / transaction.
-