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
-
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, uncappedDefaultRedisListinstance.DefaultRedisList(String key, RedisOperations<String, E> operations, int maxSize) Constructs a newDefaultRedisListinstance.DefaultRedisList(BoundListOperations<String, E> boundOps) Constructs a new, uncappedDefaultRedisListinstance.DefaultRedisList(BoundListOperations<String, E> boundOps, int maxSize) Constructs a newDefaultRedisListinstance. -
Method Summary
Modifier and TypeMethodDescriptionvoidbooleanbooleanaddAll(int index, Collection<? extends E> c) voidvoidvoidclear()intdrainTo(Collection<? super E> c) intdrainTo(Collection<? super E> c, int maxElements) element()get(int index) getFirst()getLast()getType()Returns the associated Redis type.intiterator()intlistIterator(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 e) booleanofferFirst(E e, long timeout, TimeUnit unit) booleanbooleanpeek()peekLast()poll()pollLast()pop()voidvoidvoidvoidrange(long start, long end) Get elements betweenstartandendfrom list at the bound key.intremove()remove(int index) booleanbooleanbooleanvoidsetMaxSize(int maxSize) Sets the maximum size of the (capped) list.intsize()subList(int fromIndex, int toIndex) take()takeLast()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 org.springframework.data.redis.support.collections.AbstractRedisCollection
addAll, checkResult, containsAll, equals, expire, expireAt, getExpire, getKey, getOperations, hashCode, persist, removeAll, rename, toStringMethods inherited from class java.util.AbstractCollection
contains, isEmpty, retainAll, toArray, toArrayMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.concurrent.BlockingDeque
containsMethods inherited from interface org.springframework.data.redis.core.BoundKeyOperations
expire, expire, expireAt, expireAt, getExpire, getKey, persist, renameMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
addAll, contains, containsAll, equals, hashCode, isEmpty, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArrayMethods inherited from interface org.springframework.data.redis.support.collections.RedisList
moveFirstTo, moveLastToMethods inherited from interface org.springframework.data.redis.support.collections.RedisStore
getOperations
-
Constructor Details
-
DefaultRedisList
Constructs a new, uncappedDefaultRedisListinstance.- Parameters:
key- Redis key of this list.operations-RedisOperationsfor the value type of this list.
-
DefaultRedisList
Constructs a newDefaultRedisListinstance.- Parameters:
key- Redis key of this list.operations-RedisOperationsfor the value type of this list.maxSize-- Since:
- 2.6
-
DefaultRedisList
Constructs a new, uncappedDefaultRedisListinstance.- Parameters:
boundOps-BoundListOperationsfor the value type of this list.
-
DefaultRedisList
Constructs a newDefaultRedisListinstance.- Parameters:
boundOps-BoundListOperationsfor the value type of this list.maxSize-
-
-
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.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.unit- must not be null.- Returns:
- See Also:
-
range
Description copied from interface:RedisListGet elements betweenstartandendfrom list at the bound key. -
trim
Description copied from interface:RedisListTrim list at the bound key to elements betweenstartandend. -
trim
Description copied from interface:RedisListTrim list at the bound key to elements betweenstartandend. -
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
-
addLast
-
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
- Specified by:
removeFirstin interfaceDeque<E>
-
removeFirstOccurrence
- Specified by:
removeFirstOccurrencein interfaceBlockingDeque<E>- Specified by:
removeFirstOccurrencein interfaceDeque<E>
-
removeLast
- Specified by:
removeLastin interfaceDeque<E>
-
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>- Throws:
InterruptedException
-
offerLast
- Specified by:
offerLastin interfaceBlockingDeque<E>- Throws:
InterruptedException
-
pollFirst
- Specified by:
pollFirstin interfaceBlockingDeque<E>- Throws:
InterruptedException
-
pollLast
- Specified by:
pollLastin interfaceBlockingDeque<E>- Throws:
InterruptedException
-
putFirst
- Specified by:
putFirstin interfaceBlockingDeque<E>- Throws:
InterruptedException
-
putLast
- Specified by:
putLastin interfaceBlockingDeque<E>- Throws:
InterruptedException
-
takeFirst
- Specified by:
takeFirstin interfaceBlockingDeque<E>- Throws:
InterruptedException
-
takeLast
- Specified by:
takeLastin interfaceBlockingDeque<E>- Throws:
InterruptedException
-
getType
Description copied from interface:BoundKeyOperationsReturns the associated Redis type.- Specified by:
getTypein interfaceBoundKeyOperations<E>- Returns:
- key type. null when used in pipeline / transaction.
-