Interface RSetCache<V>
- Type Parameters:
V- value
- All Superinterfaces:
Collection<V>,Iterable<V>,RCollectionAsync<V>,RDestroyable,RExpirable,RExpirableAsync,RObject,RObjectAsync,RSet<V>,RSetAsync<V>,RSetCacheAsync<V>,RSortable<Set<V>>,RSortableAsync<Set<V>>,Set<V>
- All Known Implementing Classes:
RedissonSetCache,RedissonTransactionalSetCache
Set-based cache with ability to set TTL for each object.
Current Redis implementation doesn't have set entry eviction functionality.
Thus values are checked for TTL expiration during any value read operation.
If entry expired then it doesn't returns and clean task runs asynchronous.
Clean task deletes removes 100 expired entries at once.
In addition there is EvictionScheduler. This scheduler
deletes expired entries in time interval between 5 seconds to 2 hours.
If eviction is not required then it's better to use RSet.
- Author:
- Nikita Koksharov
-
Method Summary
Modifier and TypeMethodDescriptionbooleanStores value with specified time to live.intAdds all elements contained in the specified map to this sorted set.intaddAllIfAbsent(Map<V, Duration> objects) Adds elements to this set only if they haven't been added before.intaddAllIfExist(Map<V, Duration> objects) Adds elements to this set only if they already exist.intaddAllIfGreater(Map<V, Duration> objects) Adds elements to this set only if new ttl greater than current ttl of existed elements.intaddAllIfLess(Map<V, Duration> objects) Adds elements to this set only if new ttl less than current ttl of existed elements.booleanaddIfAbsent(Duration ttl, V object) Adds element to this set only if has not been added before.booleanaddIfAbsent(Map<V, Duration> objects) Adds elements to this set only if all of them haven't been added before.booleanaddIfExists(Duration ttl, V object) Adds element to this set only if it's already exists.booleanaddIfGreater(Duration ttl, V object) Adds element to this set only if new ttl greater than current ttl of existed element.booleanAdds element to this set only if new ttl less than current ttl of existed element.intaddListener(ObjectListener listener) Adds object event listenerintsize()Returns the number of elements in cache.booleanDeprecated.Methods inherited from interface java.util.Collection
parallelStream, removeIf, streamMethods inherited from interface org.redisson.api.RCollectionAsync
addAllAsync, addAsync, containsAllAsync, containsAsync, removeAllAsync, removeAsync, retainAllAsyncMethods inherited from interface org.redisson.api.RDestroyable
destroyMethods inherited from interface org.redisson.api.RExpirable
clearExpire, expire, expire, expire, expireAt, expireAt, expireIfGreater, expireIfGreater, expireIfLess, expireIfLess, expireIfNotSet, expireIfNotSet, expireIfSet, expireIfSet, getExpireTime, remainTimeToLiveMethods inherited from interface org.redisson.api.RExpirableAsync
clearExpireAsync, expireAsync, expireAsync, expireAsync, expireAtAsync, expireAtAsync, expireIfGreaterAsync, expireIfGreaterAsync, expireIfLessAsync, expireIfLessAsync, expireIfNotSetAsync, expireIfNotSetAsync, expireIfSetAsync, expireIfSetAsync, getExpireTimeAsync, remainTimeToLiveAsyncMethods inherited from interface org.redisson.api.RObject
copy, copy, copy, copyAndReplace, copyAndReplace, delete, dump, getCodec, getIdleTime, getName, isExists, migrate, move, removeListener, rename, renamenx, restore, restore, restoreAndReplace, restoreAndReplace, sizeInMemory, touch, unlinkMethods inherited from interface org.redisson.api.RObjectAsync
copyAndReplaceAsync, copyAndReplaceAsync, copyAsync, copyAsync, copyAsync, deleteAsync, dumpAsync, getIdleTimeAsync, isExistsAsync, migrateAsync, moveAsync, removeListenerAsync, renameAsync, renamenxAsync, restoreAndReplaceAsync, restoreAndReplaceAsync, restoreAsync, restoreAsync, sizeInMemoryAsync, touchAsync, unlinkAsyncMethods inherited from interface org.redisson.api.RSet
addAllCounted, containsEach, countIntersection, countIntersection, diff, distributedIterator, distributedIterator, distributedIterator, getCountDownLatch, getFairLock, getLock, getPermitExpirableSemaphore, getReadWriteLock, getSemaphore, intersection, iterator, iterator, iterator, mapReduce, move, random, random, readAll, readDiff, readIntersection, readUnion, removeAllCounted, removeRandom, removeRandom, stream, stream, stream, tryAdd, unionMethods inherited from interface org.redisson.api.RSetAsync
addAllCountedAsync, containsEachAsync, countIntersectionAsync, countIntersectionAsync, diffAsync, intersectionAsync, moveAsync, randomAsync, randomAsync, readAllAsync, readDiffAsync, readIntersectionAsync, readUnionAsync, removeAllCountedAsync, removeRandomAsync, removeRandomAsync, tryAddAsync, unionAsyncMethods inherited from interface org.redisson.api.RSetCacheAsync
addAllAsync, addAllIfAbsentAsync, addAllIfExistAsync, addAllIfGreaterAsync, addAllIfLessAsync, addAsync, addIfAbsentAsync, addIfAbsentAsync, addIfExistsAsync, addIfGreaterAsync, addIfLessAsync, addListenerAsync, sizeAsync, tryAddAsyncMethods inherited from interface org.redisson.api.RSortable
readSort, readSort, readSort, readSort, readSort, readSort, readSortAlpha, readSortAlpha, readSortAlpha, readSortAlpha, readSortAlpha, readSortAlpha, sortTo, sortTo, sortTo, sortTo, sortTo, sortToMethods inherited from interface org.redisson.api.RSortableAsync
readSortAlphaAsync, readSortAlphaAsync, readSortAlphaAsync, readSortAlphaAsync, readSortAlphaAsync, readSortAlphaAsync, readSortAsync, readSortAsync, readSortAsync, readSortAsync, readSortAsync, readSortAsync, sortToAsync, sortToAsync, sortToAsync, sortToAsync, sortToAsync, sortToAsync
-
Method Details
-
add
Stores value with specified time to live. Value expires after specified time to live.- Parameters:
value- to addttl- - time to live for key\value entry. If0then stores infinitely.unit- - time unit- Returns:
trueif value has been added.falseif value already been in collection.
-
size
int size()Returns the number of elements in cache. This number can reflects expired elements too due to non realtime cleanup process. -
tryAdd
Deprecated.UseaddIfAbsent(Map)instead- Parameters:
ttl- - time to live for value. If0then stores infinitely.unit- - time unitvalues- - values to add- Returns:
trueif elements successfully added, otherwisefalse.
-
addIfAbsent
Adds element to this set only if has not been added before.Requires Redis 3.0.2 and higher.
- Parameters:
ttl- - object ttlobject- - object itself- Returns:
trueif element added andfalseif not.
-
addIfExists
Adds element to this set only if it's already exists.Requires Redis 3.0.2 and higher.
- Parameters:
ttl- - object ttlobject- - object itself- Returns:
trueif element added andfalseif not.
-
addIfLess
Adds element to this set only if new ttl less than current ttl of existed element.Requires Redis 6.2.0 and higher.
- Parameters:
ttl- - object ttlobject- - object itself- Returns:
trueif element added andfalseif not.
-
addIfGreater
Adds element to this set only if new ttl greater than current ttl of existed element.Requires Redis 6.2.0 and higher.
- Parameters:
ttl- - object ttlobject- - object itself- Returns:
trueif element added andfalseif not.
-
addAll
Adds all elements contained in the specified map to this sorted set. Map contains of ttl mapped by object.- Parameters:
objects- - map of elements to add- Returns:
- amount of added elements, not including already existing in this sorted set
-
addAllIfAbsent
Adds elements to this set only if they haven't been added before.Requires Redis 3.0.2 and higher.
- Parameters:
objects- map of elements to add- Returns:
- amount of added elements
-
addIfAbsent
Adds elements to this set only if all of them haven't been added before.Requires Redis 3.0.2 and higher.
- Parameters:
objects- map of elements to add- Returns:
trueif elements added andfalseif not.
-
addAllIfExist
Adds elements to this set only if they already exist.Requires Redis 3.0.2 and higher.
- Parameters:
objects- map of elements to add- Returns:
- amount of added elements
-
addAllIfGreater
Adds elements to this set only if new ttl greater than current ttl of existed elements.Requires Redis 6.2.0 and higher.
- Parameters:
objects- map of elements to add- Returns:
- amount of added elements
-
addAllIfLess
Adds elements to this set only if new ttl less than current ttl of existed elements.Requires Redis 6.2.0 and higher.
- Parameters:
objects- map of elements to add- Returns:
- amount of added elements
-
addListener
Adds object event listener- Specified by:
addListenerin interfaceRObject- Specified by:
addListenerin interfaceRSet<V>- Parameters:
listener- - object event listener- Returns:
- listener id
- See Also:
-