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 TypeMethodDescriptionboolean
Stores value with specified time to live.int
Adds all elements contained in the specified map to this sorted set.int
addAllIfAbsent
(Map<V, Duration> objects) Adds elements to this set only if they haven't been added before.int
addAllIfExist
(Map<V, Duration> objects) Adds elements to this set only if they already exist.int
addAllIfGreater
(Map<V, Duration> objects) Adds elements to this set only if new ttl greater than current ttl of existed elements.int
addAllIfLess
(Map<V, Duration> objects) Adds elements to this set only if new ttl less than current ttl of existed elements.boolean
addIfAbsent
(Duration ttl, V object) Adds element to this set only if has not been added before.boolean
addIfExists
(Duration ttl, V object) Adds element to this set only if it's already exists.boolean
addIfGreater
(Duration ttl, V object) Adds element to this set only if new ttl greater than current ttl of existed element.boolean
Adds element to this set only if new ttl less than current ttl of existed element.int
size()
Returns the number of elements in cache.boolean
Deprecated.Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface org.redisson.api.RCollectionAsync
addAllAsync, addAsync, containsAllAsync, containsAsync, removeAllAsync, removeAsync, retainAllAsync
Methods inherited from interface org.redisson.api.RDestroyable
destroy
Methods inherited from interface org.redisson.api.RExpirable
clearExpire, expire, expire, expire, expireAt, expireAt, expireIfGreater, expireIfGreater, expireIfLess, expireIfLess, expireIfNotSet, expireIfNotSet, expireIfSet, expireIfSet, getExpireTime, remainTimeToLive
Methods inherited from interface org.redisson.api.RExpirableAsync
clearExpireAsync, expireAsync, expireAsync, expireAsync, expireAtAsync, expireAtAsync, expireIfGreaterAsync, expireIfGreaterAsync, expireIfLessAsync, expireIfLessAsync, expireIfNotSetAsync, expireIfNotSetAsync, expireIfSetAsync, expireIfSetAsync, getExpireTimeAsync, remainTimeToLiveAsync
Methods inherited from interface org.redisson.api.RObject
copy, delete, dump, getCodec, getIdleTime, getName, isExists, migrate, move, removeListener, rename, renamenx, restore, restore, restoreAndReplace, restoreAndReplace, sizeInMemory, touch, unlink
Methods inherited from interface org.redisson.api.RObjectAsync
copyAsync, deleteAsync, dumpAsync, getIdleTimeAsync, isExistsAsync, migrateAsync, moveAsync, removeListenerAsync, renameAsync, renamenxAsync, restoreAndReplaceAsync, restoreAndReplaceAsync, restoreAsync, restoreAsync, sizeInMemoryAsync, touchAsync, unlinkAsync
Methods inherited from interface org.redisson.api.RSet
addAllCounted, addListener, 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, union
Methods inherited from interface org.redisson.api.RSetAsync
addAllCountedAsync, addListenerAsync, containsEachAsync, countIntersectionAsync, countIntersectionAsync, diffAsync, intersectionAsync, moveAsync, randomAsync, randomAsync, readAllAsync, readDiffAsync, readIntersectionAsync, readUnionAsync, removeAllCountedAsync, removeRandomAsync, removeRandomAsync, tryAddAsync, unionAsync
Methods inherited from interface org.redisson.api.RSetCacheAsync
addAllAsync, addAllIfAbsentAsync, addAllIfExistAsync, addAllIfGreaterAsync, addAllIfLessAsync, addAsync, addIfAbsentAsync, addIfExistsAsync, addIfGreaterAsync, addIfLessAsync, sizeAsync, tryAddAsync
Methods inherited from interface org.redisson.api.RSortable
readSort, readSort, readSort, readSort, readSort, readSort, readSortAlpha, readSortAlpha, readSortAlpha, readSortAlpha, readSortAlpha, readSortAlpha, sortTo, sortTo, sortTo, sortTo, sortTo, sortTo
Methods 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. If0
then stores infinitely.unit
- - time unit- Returns:
true
if value has been added.false
if 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(Duration, Object)
instead- Parameters:
ttl
- - time to live for value. If0
then stores infinitely.unit
- - time unitvalues
- - values to add- Returns:
true
if 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:
true
if element added andfalse
if 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:
true
if element added andfalse
if 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:
true
if element added andfalse
if 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:
true
if element added andfalse
if 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
-
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
-