Class RedissonLocalCachedMap<K,V>
- java.lang.Object
-
- org.redisson.RedissonObject
-
- org.redisson.RedissonMap<K,V>
-
- org.redisson.RedissonLocalCachedMap<K,V>
-
- All Implemented Interfaces:
ConcurrentMap<K,V>
,Map<K,V>
,RDestroyable
,RExpirable
,RExpirableAsync
,RLocalCachedMap<K,V>
,RMap<K,V>
,RMapAsync<K,V>
,RObject
,RObjectAsync
public class RedissonLocalCachedMap<K,V> extends RedissonMap<K,V> implements RLocalCachedMap<K,V>
- Author:
- Nikita Koksharov
-
-
Field Summary
Fields Modifier and Type Field Description static String
DISABLED_ACK_SUFFIX
static String
DISABLED_KEYS_SUFFIX
static String
TOPIC_SUFFIX
-
Fields inherited from class org.redisson.RedissonObject
codec, commandExecutor
-
-
Constructor Summary
Constructors Constructor Description RedissonLocalCachedMap(Codec codec, CommandAsyncExecutor connectionManager, String name, LocalCachedMapOptions<K,V> options, EvictionScheduler evictionScheduler, RedissonClient redisson)
RedissonLocalCachedMap(CommandAsyncExecutor commandExecutor, String name, LocalCachedMapOptions<K,V> options, EvictionScheduler evictionScheduler, RedissonClient redisson)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected RFuture<V>
addAndGetOperationAsync(K key, Number value)
boolean
clearExpire()
Clear an expire timeout or expire date for object.RFuture<Boolean>
clearExpireAsync()
Clear an expire timeout or expire date for object in async mode.void
clearLocalCache()
Clears local cache across all instancesRFuture<Void>
clearLocalCacheAsync()
Clears local cache across all instancesRFuture<Boolean>
containsKeyAsync(Object key)
RFuture<Boolean>
containsValueAsync(Object value)
protected Cache<CacheKey,RedissonLocalCachedMap.CacheValue>
createCache(LocalCachedMapOptions<K,V> options)
protected io.netty.buffer.ByteBuf
createSyncMessage(io.netty.buffer.ByteBuf mapKey, io.netty.buffer.ByteBuf mapValue, CacheKey cacheKey)
RFuture<Boolean>
deleteAsync()
Delete object in async modevoid
destroy()
Destroys object when it's not necessary anymore.io.netty.buffer.ByteBuf
encode(Object value)
boolean
expire(long timeToLive, TimeUnit timeUnit)
Set a timeout for object.RFuture<Boolean>
expireAsync(long timeToLive, TimeUnit timeUnit)
Set a timeout for object in async mode.boolean
expireAt(long timestamp)
Set an expire date for object.boolean
expireAt(Date timestamp)
Set an expire date for object.RFuture<Boolean>
expireAtAsync(long timestamp)
Set an expire date for object in async mode.RFuture<Boolean>
expireAtAsync(Date timestamp)
Set an expire date for object in async mode.RFuture<Boolean>
fastPutIfAbsentAsync(K key, V value)
Associates the specifiedvalue
with the specifiedkey
only if there is no any association with specifiedkey
.protected RFuture<Boolean>
fastPutOperationAsync(K key, V value)
protected RFuture<Long>
fastRemoveOperationAsync(K... keys)
protected RFuture<List<Long>>
fastRemoveOperationBatchAsync(K... keys)
RFuture<Boolean>
fastReplaceAsync(K key, V value)
Replaces previous value with a newvalue
associated with thekey
.protected RFuture<Boolean>
fastReplaceOperationAsync(K key, V value)
protected static byte[]
generateId()
protected static byte[]
generateLogEntryId(byte[] keyHash)
RFuture<Map<K,V>>
getAllAsync(Set<K> keys)
Gets a map slice contained the mappings with definedkeys
by one operation.RFuture<V>
getAsync(Object key)
Returns the value to which the specified key is mapped, ornull
if this map contains no mapping for the key.void
preloadCache()
Pre-warm the cached values.protected RFuture<Void>
putAllOperationAsync(Map<? extends K,? extends V> map)
RFuture<V>
putIfAbsentAsync(K key, V value)
Associates the specifiedvalue
with the specifiedkey
only if there is no any association with specifiedkey
.protected RFuture<V>
putOperationAsync(K key, V value)
RFuture<Set<Map.Entry<K,V>>>
readAllEntrySetAsync()
Read all map entries at onceRFuture<Map<K,V>>
readAllMapAsync()
Read all map as local instance at onceRFuture<Collection<V>>
readAllValuesAsync()
Read all values at oncelong
remainTimeToLive()
Remaining time to live of Redisson object that has a timeoutRFuture<Long>
remainTimeToLiveAsync()
Remaining time to live of Redisson object that has a timeoutRFuture<Boolean>
removeAsync(Object key, Object value)
Removeskey
from map only if it associated withvalue
.protected RFuture<Boolean>
removeOperationAsync(Object key, Object value)
protected RFuture<V>
removeOperationAsync(K key)
RFuture<V>
replaceAsync(K key, V value)
Replaces previous value with a newvalue
associated with thekey
.RFuture<Boolean>
replaceAsync(K key, V oldValue, V newValue)
Replaces previousoldValue
with anewValue
associated with thekey
.protected RFuture<V>
replaceOperationAsync(K key, V value)
protected RFuture<Boolean>
replaceOperationAsync(K key, V oldValue, V newValue)
CacheKey
toCacheKey(Object key)
-
Methods inherited from class org.redisson.RedissonMap
addAndGet, addAndGetAsync, checkKey, checkValue, clear, containsKey, containsValue, entryIterator, entrySet, entrySet, entrySet, entrySet, equals, fastPut, fastPutAsync, fastPutIfAbsent, fastPutIfAbsentOperationAsync, fastRemove, fastRemoveAsync, fastReplace, get, getAll, getAllOperationAsync, getLock, getLockName, getOperationAsync, getReadWriteLock, hashCode, hasNoLoader, hasNoWriter, isEmpty, keyIterator, keySet, keySet, keySet, keySet, loadAll, loadAll, loadAllAsync, loadAllAsync, mapReduce, mapWriterFuture, put, putAll, putAll, putAllAsync, putAllAsync, putAsync, putIfAbsent, putIfAbsentOperationAsync, readAllEntrySet, readAllKeySet, readAllKeySetAsync, readAllMap, readAllValues, remove, remove, removeAsync, replace, replace, scanIterator, scanIteratorAsync, size, sizeAsync, valueIterator, values, values, values, values, valueSize, valueSizeAsync
-
Methods inherited from class org.redisson.RedissonObject
await, copy, copyAsync, delete, dump, dumpAsync, encode, encode, encodeMapKey, encodeMapKeys, encodeMapValue, encodeMapValues, get, getCodec, getName, getName, isExists, isExistsAsync, migrate, migrateAsync, move, moveAsync, prefixName, rename, renameAsync, renamenx, renamenxAsync, restore, restore, restoreAndReplace, restoreAndReplace, restoreAndReplaceAsync, restoreAndReplaceAsync, restoreAsync, restoreAsync, suffixName, toSeconds, touch, touchAsync, unlink, unlinkAsync
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.concurrent.ConcurrentMap
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, replaceAll
-
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, equals, hashCode, isEmpty, size
-
Methods inherited from interface org.redisson.api.RExpirable
clearExpire, expire, expireAt, expireAt, remainTimeToLive
-
Methods inherited from interface org.redisson.api.RExpirableAsync
clearExpireAsync, expireAsync, expireAtAsync, expireAtAsync, remainTimeToLiveAsync
-
Methods inherited from interface org.redisson.api.RMap
addAndGet, entrySet, entrySet, entrySet, entrySet, fastPut, fastPutIfAbsent, fastRemove, fastReplace, get, getAll, getLock, getReadWriteLock, keySet, keySet, keySet, keySet, loadAll, loadAll, mapReduce, put, putAll, putAll, putIfAbsent, readAllEntrySet, readAllKeySet, readAllMap, readAllValues, remove, remove, replace, replace, values, values, values, values, valueSize
-
Methods inherited from interface org.redisson.api.RMapAsync
addAndGetAsync, fastPutAsync, fastRemoveAsync, loadAllAsync, loadAllAsync, putAllAsync, putAllAsync, putAsync, readAllKeySetAsync, removeAsync, sizeAsync, valueSizeAsync
-
Methods inherited from interface org.redisson.api.RObject
copy, delete, dump, getCodec, getName, isExists, migrate, move, rename, renamenx, restore, restore, restoreAndReplace, restoreAndReplace, touch, unlink
-
Methods inherited from interface org.redisson.api.RObjectAsync
copyAsync, dumpAsync, isExistsAsync, migrateAsync, moveAsync, renameAsync, renamenxAsync, restoreAndReplaceAsync, restoreAndReplaceAsync, restoreAsync, restoreAsync, touchAsync, unlinkAsync
-
-
-
-
Field Detail
-
TOPIC_SUFFIX
public static final String TOPIC_SUFFIX
- See Also:
- Constant Field Values
-
DISABLED_KEYS_SUFFIX
public static final String DISABLED_KEYS_SUFFIX
- See Also:
- Constant Field Values
-
DISABLED_ACK_SUFFIX
public static final String DISABLED_ACK_SUFFIX
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
RedissonLocalCachedMap
public RedissonLocalCachedMap(CommandAsyncExecutor commandExecutor, String name, LocalCachedMapOptions<K,V> options, EvictionScheduler evictionScheduler, RedissonClient redisson)
-
RedissonLocalCachedMap
public RedissonLocalCachedMap(Codec codec, CommandAsyncExecutor connectionManager, String name, LocalCachedMapOptions<K,V> options, EvictionScheduler evictionScheduler, RedissonClient redisson)
-
-
Method Detail
-
createCache
protected Cache<CacheKey,RedissonLocalCachedMap.CacheValue> createCache(LocalCachedMapOptions<K,V> options)
-
containsKeyAsync
public RFuture<Boolean> containsKeyAsync(Object key)
- Specified by:
containsKeyAsync
in interfaceRMapAsync<K,V>
- Overrides:
containsKeyAsync
in classRedissonMap<K,V>
-
containsValueAsync
public RFuture<Boolean> containsValueAsync(Object value)
- Specified by:
containsValueAsync
in interfaceRMapAsync<K,V>
- Overrides:
containsValueAsync
in classRedissonMap<K,V>
-
getAsync
public RFuture<V> getAsync(Object key)
Description copied from interface:RMapAsync
Returns the value to which the specified key is mapped, ornull
if this map contains no mapping for the key.If map doesn't contain value for specified key and
MapLoader
is defined then value will be loaded in read-through mode.
-
generateId
protected static byte[] generateId()
-
generateLogEntryId
protected static byte[] generateLogEntryId(byte[] keyHash)
-
putOperationAsync
protected RFuture<V> putOperationAsync(K key, V value)
- Overrides:
putOperationAsync
in classRedissonMap<K,V>
-
createSyncMessage
protected io.netty.buffer.ByteBuf createSyncMessage(io.netty.buffer.ByteBuf mapKey, io.netty.buffer.ByteBuf mapValue, CacheKey cacheKey)
-
fastPutOperationAsync
protected RFuture<Boolean> fastPutOperationAsync(K key, V value)
- Overrides:
fastPutOperationAsync
in classRedissonMap<K,V>
-
destroy
public void destroy()
Description copied from interface:RDestroyable
Destroys object when it's not necessary anymore.- Specified by:
destroy
in interfaceRDestroyable
-
removeOperationAsync
protected RFuture<V> removeOperationAsync(K key)
- Overrides:
removeOperationAsync
in classRedissonMap<K,V>
-
fastRemoveOperationBatchAsync
protected RFuture<List<Long>> fastRemoveOperationBatchAsync(K... keys)
- Overrides:
fastRemoveOperationBatchAsync
in classRedissonMap<K,V>
-
fastRemoveOperationAsync
protected RFuture<Long> fastRemoveOperationAsync(K... keys)
- Overrides:
fastRemoveOperationAsync
in classRedissonMap<K,V>
-
deleteAsync
public RFuture<Boolean> deleteAsync()
Description copied from interface:RObjectAsync
Delete object in async mode- Specified by:
deleteAsync
in interfaceRObjectAsync
- Overrides:
deleteAsync
in classRedissonObject
- Returns:
true
if object was deletedfalse
if not
-
getAllAsync
public RFuture<Map<K,V>> getAllAsync(Set<K> keys)
Description copied from interface:RMapAsync
Gets a map slice contained the mappings with definedkeys
by one operation.If map doesn't contain value/values for specified key/keys and
MapLoader
is defined then value/values will be loaded in read-through mode.The returned map is NOT backed by the original map.
- Specified by:
getAllAsync
in interfaceRMapAsync<K,V>
- Overrides:
getAllAsync
in classRedissonMap<K,V>
- Parameters:
keys
- - map keys- Returns:
- Map slice
-
putAllOperationAsync
protected RFuture<Void> putAllOperationAsync(Map<? extends K,? extends V> map)
- Overrides:
putAllOperationAsync
in classRedissonMap<K,V>
-
addAndGetOperationAsync
protected RFuture<V> addAndGetOperationAsync(K key, Number value)
- Overrides:
addAndGetOperationAsync
in classRedissonMap<K,V>
-
fastPutIfAbsentAsync
public RFuture<Boolean> fastPutIfAbsentAsync(K key, V value)
Description copied from interface:RMapAsync
Associates the specifiedvalue
with the specifiedkey
only if there is no any association with specifiedkey
.Works faster than
but not returning the previous value associated withRMapAsync.putIfAbsentAsync(Object, Object)
key
If
MapWriter
is defined then new map entry is stored in write-through mode.- Specified by:
fastPutIfAbsentAsync
in interfaceRMapAsync<K,V>
- Overrides:
fastPutIfAbsentAsync
in classRedissonMap<K,V>
- Parameters:
key
- - map keyvalue
- - map value- Returns:
true
if key is a new one in the hash and value was set.false
if key already exists in the hash and change hasn't been made.
-
readAllValuesAsync
public RFuture<Collection<V>> readAllValuesAsync()
Description copied from interface:RMapAsync
Read all values at once- Specified by:
readAllValuesAsync
in interfaceRMapAsync<K,V>
- Overrides:
readAllValuesAsync
in classRedissonMap<K,V>
- Returns:
- values
-
readAllMapAsync
public RFuture<Map<K,V>> readAllMapAsync()
Description copied from interface:RMapAsync
Read all map as local instance at once- Specified by:
readAllMapAsync
in interfaceRMapAsync<K,V>
- Overrides:
readAllMapAsync
in classRedissonMap<K,V>
- Returns:
- map
-
preloadCache
public void preloadCache()
Description copied from interface:RLocalCachedMap
Pre-warm the cached values. Not guaranteed to load ALL values, but statistically will preload approximately all (all if no concurrent mutating activity) Intended for use with no-eviction caches where entire maps are locally cached- Specified by:
preloadCache
in interfaceRLocalCachedMap<K,V>
-
clearLocalCache
public void clearLocalCache()
Description copied from interface:RLocalCachedMap
Clears local cache across all instances- Specified by:
clearLocalCache
in interfaceRLocalCachedMap<K,V>
-
clearLocalCacheAsync
public RFuture<Void> clearLocalCacheAsync()
Description copied from interface:RLocalCachedMap
Clears local cache across all instances- Specified by:
clearLocalCacheAsync
in interfaceRLocalCachedMap<K,V>
- Returns:
- void
-
readAllEntrySetAsync
public RFuture<Set<Map.Entry<K,V>>> readAllEntrySetAsync()
Description copied from interface:RMapAsync
Read all map entries at once- Specified by:
readAllEntrySetAsync
in interfaceRMapAsync<K,V>
- Overrides:
readAllEntrySetAsync
in classRedissonMap<K,V>
- Returns:
- entries
-
fastReplaceAsync
public RFuture<Boolean> fastReplaceAsync(K key, V value)
Description copied from interface:RMapAsync
Replaces previous value with a newvalue
associated with thekey
.Works faster than
but not returning the previous value associated withRMapAsync.replaceAsync(Object, Object)
key
If
MapWriter
is defined then new map entry is stored in write-through mode.- Specified by:
fastReplaceAsync
in interfaceRMapAsync<K,V>
- Overrides:
fastReplaceAsync
in classRedissonMap<K,V>
- Parameters:
key
- - map keyvalue
- - map value- Returns:
true
if key exists and value was updated.false
if key doesn't exists and value wasn't updated.
-
fastReplaceOperationAsync
protected RFuture<Boolean> fastReplaceOperationAsync(K key, V value)
- Overrides:
fastReplaceOperationAsync
in classRedissonMap<K,V>
-
replaceOperationAsync
protected RFuture<V> replaceOperationAsync(K key, V value)
- Overrides:
replaceOperationAsync
in classRedissonMap<K,V>
-
replaceAsync
public RFuture<V> replaceAsync(K key, V value)
Description copied from interface:RMapAsync
Replaces previous value with a newvalue
associated with thekey
. If there wasn't any association before then method returnsnull
.If
MapWriter
is defined then newvalue
is written in write-through mode.- Specified by:
replaceAsync
in interfaceRMapAsync<K,V>
- Overrides:
replaceAsync
in classRedissonMap<K,V>
- Parameters:
key
- - map keyvalue
- - map value- Returns:
- previous associated value
or
null
if there wasn't any association and change hasn't been made
-
replaceOperationAsync
protected RFuture<Boolean> replaceOperationAsync(K key, V oldValue, V newValue)
- Overrides:
replaceOperationAsync
in classRedissonMap<K,V>
-
replaceAsync
public RFuture<Boolean> replaceAsync(K key, V oldValue, V newValue)
Description copied from interface:RMapAsync
Replaces previousoldValue
with anewValue
associated with thekey
. If previous value doesn't exist or equal tooldValue
then method returnsfalse
.If
MapWriter
is defined thennewValue
is written in write-through mode.- Specified by:
replaceAsync
in interfaceRMapAsync<K,V>
- Overrides:
replaceAsync
in classRedissonMap<K,V>
- Parameters:
key
- - map keyoldValue
- - map old valuenewValue
- - map new value- Returns:
true
if value has been replaced otherwisefalse
.
-
removeOperationAsync
protected RFuture<Boolean> removeOperationAsync(Object key, Object value)
- Overrides:
removeOperationAsync
in classRedissonMap<K,V>
-
removeAsync
public RFuture<Boolean> removeAsync(Object key, Object value)
Description copied from interface:RMapAsync
Removeskey
from map only if it associated withvalue
.If
MapWriter
is defined thenkey
is deleted in write-through mode.- Specified by:
removeAsync
in interfaceRMapAsync<K,V>
- Overrides:
removeAsync
in classRedissonMap<K,V>
- Parameters:
key
- - map keyvalue
- - map value- Returns:
true
if map entry has been replaced otherwisefalse
.
-
putIfAbsentAsync
public RFuture<V> putIfAbsentAsync(K key, V value)
Description copied from interface:RMapAsync
Associates the specifiedvalue
with the specifiedkey
only if there is no any association with specifiedkey
.If
MapWriter
is defined then new map entry is stored in write-through mode.- Specified by:
putIfAbsentAsync
in interfaceRMapAsync<K,V>
- Overrides:
putIfAbsentAsync
in classRedissonMap<K,V>
- Parameters:
key
- - map keyvalue
- - map value- Returns:
null
if key is a new one in the hash and value was set. Previous value if key already exists in the hash and change hasn't been made.
-
encode
public io.netty.buffer.ByteBuf encode(Object value)
- Overrides:
encode
in classRedissonObject
-
expire
public boolean expire(long timeToLive, TimeUnit timeUnit)
Description copied from interface:RExpirable
Set a timeout for object. After the timeout has expired, the key will automatically be deleted.- Specified by:
expire
in interfaceRExpirable
- Parameters:
timeToLive
- - timeout before object will be deletedtimeUnit
- - timeout time unit- Returns:
true
if the timeout was set andfalse
if not
-
expireAsync
public RFuture<Boolean> expireAsync(long timeToLive, TimeUnit timeUnit)
Description copied from interface:RExpirableAsync
Set a timeout for object in async mode. After the timeout has expired, the key will automatically be deleted.- Specified by:
expireAsync
in interfaceRExpirableAsync
- Parameters:
timeToLive
- - timeout before object will be deletedtimeUnit
- - timeout time unit- Returns:
true
if the timeout was set andfalse
if not
-
expireAt
public boolean expireAt(long timestamp)
Description copied from interface:RExpirable
Set an expire date for object. When expire date comes the key will automatically be deleted.- Specified by:
expireAt
in interfaceRExpirable
- Parameters:
timestamp
- - expire date in milliseconds (Unix timestamp)- Returns:
true
if the timeout was set andfalse
if not
-
expireAtAsync
public RFuture<Boolean> expireAtAsync(long timestamp)
Description copied from interface:RExpirableAsync
Set an expire date for object in async mode. When expire date comes the key will automatically be deleted.- Specified by:
expireAtAsync
in interfaceRExpirableAsync
- Parameters:
timestamp
- - expire date in milliseconds (Unix timestamp)- Returns:
true
if the timeout was set andfalse
if not
-
expireAt
public boolean expireAt(Date timestamp)
Description copied from interface:RExpirable
Set an expire date for object. When expire date comes the key will automatically be deleted.- Specified by:
expireAt
in interfaceRExpirable
- Parameters:
timestamp
- - expire date- Returns:
true
if the timeout was set andfalse
if not
-
expireAtAsync
public RFuture<Boolean> expireAtAsync(Date timestamp)
Description copied from interface:RExpirableAsync
Set an expire date for object in async mode. When expire date comes the key will automatically be deleted.- Specified by:
expireAtAsync
in interfaceRExpirableAsync
- Parameters:
timestamp
- - expire date- Returns:
true
if the timeout was set andfalse
if not
-
clearExpire
public boolean clearExpire()
Description copied from interface:RExpirable
Clear an expire timeout or expire date for object.- Specified by:
clearExpire
in interfaceRExpirable
- Returns:
true
if timeout was removedfalse
if object does not exist or does not have an associated timeout
-
clearExpireAsync
public RFuture<Boolean> clearExpireAsync()
Description copied from interface:RExpirableAsync
Clear an expire timeout or expire date for object in async mode. Object will not be deleted.- Specified by:
clearExpireAsync
in interfaceRExpirableAsync
- Returns:
true
if the timeout was cleared andfalse
if not
-
remainTimeToLive
public long remainTimeToLive()
Description copied from interface:RExpirable
Remaining time to live of Redisson object that has a timeout- Specified by:
remainTimeToLive
in interfaceRExpirable
- Returns:
- time in milliseconds -2 if the key does not exist. -1 if the key exists but has no associated expire.
-
remainTimeToLiveAsync
public RFuture<Long> remainTimeToLiveAsync()
Description copied from interface:RExpirableAsync
Remaining time to live of Redisson object that has a timeout- Specified by:
remainTimeToLiveAsync
in interfaceRExpirableAsync
- Returns:
- time in milliseconds -2 if the key does not exist. -1 if the key exists but has no associated expire.
-
-