Package org.redisson

Class RedissonMapCache<K,V>

Type Parameters:
K - key
V - value
All Implemented Interfaces:
ConcurrentMap<K,V>, Map<K,V>, RDestroyable, RExpirable, RExpirableAsync, RMap<K,V>, RMapAsync<K,V>, RMapCache<K,V>, RMapCacheAsync<K,V>, RObject, RObjectAsync
Direct Known Subclasses:
RedissonTransactionalMapCache

public class RedissonMapCache<K,V> extends RedissonMap<K,V> implements RMapCache<K,V>

Map-based cache with ability to set TTL for each entry via put(Object, Object, long, TimeUnit) or putIfAbsent(Object, Object, long, TimeUnit) methods. And therefore has an complex lua-scripts inside.

Current redis implementation doesnt have map entry eviction functionality. Thus entries are checked for TTL expiration during any key/value/entry read operation. If key/value/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 RedissonMap object.

Author:
Nikita Koksharov
  • Constructor Details

  • Method Details

    • trySetMaxSize

      public boolean trySetMaxSize(int maxSize)
      Description copied from interface: RMapCache
      Tries to set max size of the map. Superfluous elements are evicted using LRU algorithm.
      Specified by:
      trySetMaxSize in interface RMapCache<K,V>
      Parameters:
      maxSize - - max size
      Returns:
      true if max size has been successfully set, otherwise false. If 0 the cache is unbounded (default).
    • trySetMaxSize

      public boolean trySetMaxSize(int maxSize, EvictionMode mode)
      Description copied from interface: RMapCache
      Tries to set max size of the map. Superfluous elements are evicted using defined algorithm.
      Specified by:
      trySetMaxSize in interface RMapCache<K,V>
      Parameters:
      maxSize - - max size
      mode - - eviction mode
      Returns:
      true if max size has been successfully set, otherwise false.
    • trySetMaxSizeAsync

      public RFuture<Boolean> trySetMaxSizeAsync(int maxSize)
      Description copied from interface: RMapCacheAsync
      Tries to set max size of the map. Superfluous elements are evicted using LRU algorithm by default.
      Specified by:
      trySetMaxSizeAsync in interface RMapCacheAsync<K,V>
      Parameters:
      maxSize - - max size
      Returns:
      true if max size has been successfully set, otherwise false.
    • trySetMaxSizeAsync

      public RFuture<Boolean> trySetMaxSizeAsync(int maxSize, EvictionMode mode)
      Description copied from interface: RMapCacheAsync
      Tries to set max size of the map. Superfluous elements are evicted using defined algorithm.
      Specified by:
      trySetMaxSizeAsync in interface RMapCacheAsync<K,V>
      Parameters:
      maxSize - - max size
      mode - - eviction mode
      Returns:
      true if max size has been successfully set, otherwise false.
    • setMaxSize

      public void setMaxSize(int maxSize)
      Description copied from interface: RMapCache
      Sets max size of the map and overrides current value. Superfluous elements are evicted using LRU algorithm.
      Specified by:
      setMaxSize in interface RMapCache<K,V>
      Parameters:
      maxSize - - max size If 0 the cache is unbounded (default).
    • setMaxSize

      public void setMaxSize(int maxSize, EvictionMode mode)
      Description copied from interface: RMapCache
      Sets max size of the map and overrides current value. Superfluous elements are evicted using defined algorithm.
      Specified by:
      setMaxSize in interface RMapCache<K,V>
      Parameters:
      maxSize - - max size
      mode - - eviction mode
    • setMaxSizeAsync

      public RFuture<Void> setMaxSizeAsync(int maxSize)
      Description copied from interface: RMapCacheAsync
      Sets max size of the map and overrides current value. Superfluous elements are evicted using LRU algorithm by default.
      Specified by:
      setMaxSizeAsync in interface RMapCacheAsync<K,V>
      Parameters:
      maxSize - - max size
      Returns:
      void
    • setMaxSizeAsync

      public RFuture<Void> setMaxSizeAsync(int maxSize, EvictionMode mode)
      Description copied from interface: RMapCacheAsync
      Sets max size of the map and overrides current value. Superfluous elements are evicted using defined algorithm.
      Specified by:
      setMaxSizeAsync in interface RMapCacheAsync<K,V>
      Parameters:
      maxSize - - max size
      mode - - eviction mode
      Returns:
      void
    • containsKeyOperationAsync

      protected RFuture<Boolean> containsKeyOperationAsync(String name, Object key)
      Overrides:
      containsKeyOperationAsync in class RedissonMap<K,V>
    • containsValueAsync

      public RFuture<Boolean> containsValueAsync(Object value)
      Description copied from interface: RMapAsync
      Returns true if this map contains any map entry with specified value, otherwise false
      Specified by:
      containsValueAsync in interface RMapAsync<K,V>
      Overrides:
      containsValueAsync in class RedissonMap<K,V>
      Parameters:
      value - - map value
      Returns:
      true if this map contains any map entry with specified value, otherwise false
    • getAllOperationAsync

      public RFuture<Map<K,V>> getAllOperationAsync(Set<K> keys)
      Overrides:
      getAllOperationAsync in class RedissonMap<K,V>
    • putIfAbsent

      public V putIfAbsent(K key, V value, long ttl, TimeUnit ttlUnit)
      Description copied from interface: RMapCache
      If the specified key is not already associated with a value, associate it with the given value.

      Stores value mapped by key with specified time to live. Entry expires after specified time to live.

      Specified by:
      putIfAbsent in interface RMapCache<K,V>
      Parameters:
      key - - map key
      value - - map value
      ttl - - time to live for key\value entry. If 0 then stores infinitely.
      ttlUnit - - time unit
      Returns:
      current associated value
    • putIfAbsentAsync

      public RFuture<V> putIfAbsentAsync(K key, V value, long ttl, TimeUnit ttlUnit)
      Description copied from interface: RMapCacheAsync
      If the specified key is not already associated with a value, associate it with the given value.

      Stores value mapped by key with specified time to live. Entry expires after specified time to live. If the map previously contained a mapping for the key, the old value is replaced by the specified value.

      Specified by:
      putIfAbsentAsync in interface RMapCacheAsync<K,V>
      Parameters:
      key - - map key
      value - - map value
      ttl - - time to live for key\value entry. If 0 then stores infinitely.
      ttlUnit - - time unit
      Returns:
      previous associated value
    • putIfAbsent

      public V putIfAbsent(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit)
      Description copied from interface: RMapCache
      If the specified key is not already associated with a value, associate it with the given value.

      Stores value mapped by key with specified time to live and max idle time. Entry expires when specified time to live or max idle time has expired.

      Specified by:
      putIfAbsent in interface RMapCache<K,V>
      Parameters:
      key - - map key
      value - - map value
      ttl - - time to live for key\value entry. If 0 then time to live doesn't affect entry expiration.
      ttlUnit - - time unit
      maxIdleTime - - max idle time for key\value entry. If 0 then max idle time doesn't affect entry expiration.
      maxIdleUnit - - time unit

      if maxIdleTime and ttl params are equal to 0 then entry stores infinitely.

      Returns:
      current associated value
    • putIfAbsentAsync

      public RFuture<V> putIfAbsentAsync(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit)
      Description copied from interface: RMapCacheAsync
      If the specified key is not already associated with a value, associate it with the given value.

      Stores value mapped by key with specified time to live and max idle time. Entry expires when specified time to live or max idle time has expired.

      If the map previously contained a mapping for the key, the old value is replaced by the specified value.

      Specified by:
      putIfAbsentAsync in interface RMapCacheAsync<K,V>
      Parameters:
      key - - map key
      value - - map value
      ttl - - time to live for key\value entry. If 0 then time to live doesn't affect entry expiration.
      ttlUnit - - time unit
      maxIdleTime - - max idle time for key\value entry. If 0 then max idle time doesn't affect entry expiration.
      maxIdleUnit - - time unit

      if maxIdleTime and ttl params are equal to 0 then entry stores infinitely.

      Returns:
      previous associated value
    • removeOperationAsync

      protected RFuture<Boolean> removeOperationAsync(Object key, Object value)
      Overrides:
      removeOperationAsync in class RedissonMap<K,V>
    • getOperationAsync

      public RFuture<V> getOperationAsync(K key)
      Overrides:
      getOperationAsync in class RedissonMap<K,V>
    • put

      public V put(K key, V value, long ttl, TimeUnit unit)
      Description copied from interface: RMapCache
      Stores value mapped by key with specified time to live. Entry expires after specified time to live.

      If the map previously contained a mapping for the key, the old value is replaced by the specified value.

      Specified by:
      put in interface RMapCache<K,V>
      Parameters:
      key - - map key
      value - - map value
      ttl - - time to live for key\value entry. If 0 then stores infinitely.
      unit - - time unit
      Returns:
      previous associated value
    • putOperationAsync

      protected RFuture<V> putOperationAsync(K key, V value)
      Overrides:
      putOperationAsync in class RedissonMap<K,V>
    • putIfExistsOperationAsync

      protected RFuture<V> putIfExistsOperationAsync(K key, V value)
      Overrides:
      putIfExistsOperationAsync in class RedissonMap<K,V>
    • putIfAbsentOperationAsync

      protected RFuture<V> putIfAbsentOperationAsync(K key, V value)
      Overrides:
      putIfAbsentOperationAsync in class RedissonMap<K,V>
    • putAll

      public void putAll(Map<? extends K,? extends V> map, long ttl, TimeUnit ttlUnit)
      Description copied from interface: RMapCache
      Associates the specified value with the specified key in batch.

      If MapWriter is defined then new map entries will be stored in write-through mode.

      Specified by:
      putAll in interface RMapCache<K,V>
      Parameters:
      map - - mappings to be stored in this map
      ttl - - time to live for all key\value entries. If 0 then stores infinitely.
      ttlUnit - - time unit
    • putAllAsync

      public RFuture<Void> putAllAsync(Map<? extends K,? extends V> map, long ttl, TimeUnit ttlUnit)
      Description copied from interface: RMapCacheAsync
      Associates the specified value with the specified key in batch.

      If MapWriter is defined then new map entries are stored in write-through mode.

      Specified by:
      putAllAsync in interface RMapCacheAsync<K,V>
      Parameters:
      map - - mappings to be stored in this map
      ttl - - time to live for all key\value entries. If 0 then stores infinitely.
      ttlUnit - - time unit
      Returns:
      void
    • addAndGet

      public V addAndGet(K key, Number value)
      Description copied from interface: RMap
      Adds the given delta to the current value by mapped key. Works only for numeric values!
      Specified by:
      addAndGet in interface RMap<K,V>
      Overrides:
      addAndGet in class RedissonMap<K,V>
      Parameters:
      key - - map key
      value - the value to add
      Returns:
      the updated value
    • addAndGetOperationAsync

      protected RFuture<V> addAndGetOperationAsync(K key, Number value)
      Overrides:
      addAndGetOperationAsync in class RedissonMap<K,V>
    • fastPut

      public boolean fastPut(K key, V value, long ttl, TimeUnit ttlUnit)
      Description copied from interface: RMapCache
      Stores value mapped by key with specified time to live. Entry expires after specified time to live.

      If the map previously contained a mapping for the key, the old value is replaced by the specified value.

      Works faster than usual RMapCache.put(Object, Object, long, TimeUnit) as it not returns previous value.

      Specified by:
      fastPut in interface RMapCache<K,V>
      Parameters:
      key - - map key
      value - - map value
      ttl - - time to live for key\value entry. If 0 then stores infinitely.
      ttlUnit - - time unit
      Returns:
      true if key is a new key in the hash and value was set. false if key already exists in the hash and the value was updated.
    • fastPutAsync

      public RFuture<Boolean> fastPutAsync(K key, V value, long ttl, TimeUnit ttlUnit)
      Description copied from interface: RMapCacheAsync
      Stores value mapped by key with specified time to live. Entry expires after specified time to live.

      If the map previously contained a mapping for the key, the old value is replaced by the specified value.

      Works faster than usual RMapCacheAsync.putAsync(Object, Object, long, TimeUnit) as it not returns previous value.

      Specified by:
      fastPutAsync in interface RMapCacheAsync<K,V>
      Parameters:
      key - - map key
      value - - map value
      ttl - - time to live for key\value entry. If 0 then stores infinitely.
      ttlUnit - - time unit
      Returns:
      true if key is a new key in the hash and value was set. false if key already exists in the hash and the value was updated.
    • fastPut

      public boolean fastPut(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit)
      Description copied from interface: RMapCache
      Stores value mapped by key with specified time to live and max idle time. Entry expires when specified time to live or max idle time has expired.

      If the map previously contained a mapping for the key, the old value is replaced by the specified value.

      Works faster than usual RMapCache.put(Object, Object, long, TimeUnit, long, TimeUnit) as it not returns previous value.

      Specified by:
      fastPut in interface RMapCache<K,V>
      Parameters:
      key - - map key
      value - - map value
      ttl - - time to live for key\value entry. If 0 then time to live doesn't affect entry expiration.
      ttlUnit - - time unit
      maxIdleTime - - max idle time for key\value entry. If 0 then max idle time doesn't affect entry expiration.
      maxIdleUnit - - time unit

      if maxIdleTime and ttl params are equal to 0 then entry stores infinitely.

      Returns:
      true if key is a new key in the hash and value was set. false if key already exists in the hash and the value was updated.
    • fastPutAsync

      public RFuture<Boolean> fastPutAsync(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit)
      Description copied from interface: RMapCacheAsync
      Stores value mapped by key with specified time to live and max idle time. Entry expires when specified time to live or max idle time has expired.

      If the map previously contained a mapping for the key, the old value is replaced by the specified value.

      Works faster than usual RMapCacheAsync.putAsync(Object, Object, long, TimeUnit, long, TimeUnit) as it not returns previous value.

      Specified by:
      fastPutAsync in interface RMapCacheAsync<K,V>
      Parameters:
      key - - map key
      value - - map value
      ttl - - time to live for key\value entry. If 0 then time to live doesn't affect entry expiration.
      ttlUnit - - time unit
      maxIdleTime - - max idle time for key\value entry. If 0 then max idle time doesn't affect entry expiration.
      maxIdleUnit - - time unit

      if maxIdleTime and ttl params are equal to 0 then entry stores infinitely.

      Returns:
      true if key is a new key in the hash and value was set. false if key already exists in the hash and the value was updated.
    • fastPutOperationAsync

      protected RFuture<Boolean> fastPutOperationAsync(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit)
    • updateEntryExpiration

      public boolean updateEntryExpiration(K key, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit)
      Description copied from interface: RMapCache
      Updates time to live and max idle time of specified entry by key. Entry expires when specified time to live or max idle time was reached.

      Returns false if entry already expired or doesn't exist, otherwise returns true.

      Specified by:
      updateEntryExpiration in interface RMapCache<K,V>
      Parameters:
      key - - map key
      ttl - - time to live for key\value entry. If 0 then time to live doesn't affect entry expiration.
      ttlUnit - - time unit
      maxIdleTime - - max idle time for key\value entry. If 0 then max idle time doesn't affect entry expiration.
      maxIdleUnit - - time unit

      if maxIdleTime and ttl params are equal to 0 then entry stores infinitely.

      Returns:
      returns false if entry already expired or doesn't exist, otherwise returns true.
    • updateEntryExpirationAsync

      public RFuture<Boolean> updateEntryExpirationAsync(K key, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit)
      Description copied from interface: RMapCacheAsync
      Updates time to live and max idle time of specified entry by key. Entry expires when specified time to live or max idle time was reached.

      Returns false if entry already expired or doesn't exist, otherwise returns true.

      Specified by:
      updateEntryExpirationAsync in interface RMapCacheAsync<K,V>
      Parameters:
      key - - map key
      ttl - - time to live for key\value entry. If 0 then time to live doesn't affect entry expiration.
      ttlUnit - - time unit
      maxIdleTime - - max idle time for key\value entry. If 0 then max idle time doesn't affect entry expiration.
      maxIdleUnit - - time unit

      if maxIdleTime and ttl params are equal to 0 then entry stores infinitely.

      Returns:
      returns false if entry already expired or doesn't exist, otherwise returns true.
    • putAsync

      public RFuture<V> putAsync(K key, V value, long ttl, TimeUnit ttlUnit)
      Description copied from interface: RMapCacheAsync
      Stores value mapped by key with specified time to live. Entry expires after specified time to live. If the map previously contained a mapping for the key, the old value is replaced by the specified value.
      Specified by:
      putAsync in interface RMapCacheAsync<K,V>
      Parameters:
      key - - map key
      value - - map value
      ttl - - time to live for key\value entry. If 0 then stores infinitely.
      ttlUnit - - time unit
      Returns:
      previous associated value
    • put

      public V put(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit)
      Description copied from interface: RMapCache
      Stores value mapped by key with specified time to live and max idle time. Entry expires when specified time to live or max idle time has expired.

      If the map previously contained a mapping for the key, the old value is replaced by the specified value.

      Specified by:
      put in interface RMapCache<K,V>
      Parameters:
      key - - map key
      value - - map value
      ttl - - time to live for key\value entry. If 0 then time to live doesn't affect entry expiration.
      ttlUnit - - time unit
      maxIdleTime - - max idle time for key\value entry. If 0 then max idle time doesn't affect entry expiration.
      maxIdleUnit - - time unit

      if maxIdleTime and ttl params are equal to 0 then entry stores infinitely.

      Returns:
      previous associated value
    • putAsync

      public RFuture<V> putAsync(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit)
      Description copied from interface: RMapCacheAsync
      Stores value mapped by key with specified time to live and max idle time. Entry expires when specified time to live or max idle time has expired.

      If the map previously contained a mapping for the key, the old value is replaced by the specified value.

      Specified by:
      putAsync in interface RMapCacheAsync<K,V>
      Parameters:
      key - - map key
      value - - map value
      ttl - - time to live for key\value entry. If 0 then time to live doesn't affect entry expiration.
      ttlUnit - - time unit
      maxIdleTime - - max idle time for key\value entry. If 0 then max idle time doesn't affect entry expiration.
      maxIdleUnit - - time unit

      if maxIdleTime and ttl params are equal to 0 then entry stores infinitely.

      Returns:
      previous associated value
    • putOperationAsync

      protected RFuture<V> putOperationAsync(K key, V value, long ttlTimeout, long maxIdleTimeout, long maxIdleDelta, long ttlTimeoutDelta)
    • getWithTTLOnly

      public V getWithTTLOnly(K key)
      Description copied from interface: RMapCache
      Returns the value mapped by defined key or null if value is absent.

      If map doesn't contain value for specified key and MapLoader is defined then value will be loaded in read-through mode.

      Idle time of entry is not taken into account. Entry last access time isn't modified if map limited by size.

      Specified by:
      getWithTTLOnly in interface RMapCache<K,V>
      Parameters:
      key - the key
      Returns:
      the value mapped by defined key or null if value is absent
    • getWithTTLOnlyAsync

      public RFuture<V> getWithTTLOnlyAsync(K key)
      Description copied from interface: RMapCacheAsync
      Returns the value mapped by defined key or null if value is absent.

      If map doesn't contain value for specified key and MapLoader is defined then value will be loaded in read-through mode.

      Idle time of entry is not taken into account. Entry last access time isn't modified if map limited by size.

      Specified by:
      getWithTTLOnlyAsync in interface RMapCacheAsync<K,V>
      Parameters:
      key - the key
      Returns:
      the value mapped by defined key or null if value is absent
    • remainTimeToLive

      public long remainTimeToLive(K key)
      Description copied from interface: RMapCache
      Remaining time to live of map entry associated with a key.
      Specified by:
      remainTimeToLive in interface RMapCache<K,V>
      Parameters:
      key - - map key
      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(K key)
      Description copied from interface: RMapCacheAsync
      Remaining time to live of map entry associated with a key.
      Specified by:
      remainTimeToLiveAsync in interface RMapCacheAsync<K,V>
      Parameters:
      key - - map key
      Returns:
      time in milliseconds -2 if the key does not exist. -1 if the key exists but has no associated expire.
    • removeOperationAsync

      protected RFuture<V> removeOperationAsync(K key)
      Overrides:
      removeOperationAsync in class RedissonMap<K,V>
    • fastRemoveOperationBatchAsync

      protected RFuture<List<Long>> fastRemoveOperationBatchAsync(K... keys)
      Overrides:
      fastRemoveOperationBatchAsync in class RedissonMap<K,V>
    • fastRemoveOperationAsync

      protected RFuture<Long> fastRemoveOperationAsync(K... keys)
      Overrides:
      fastRemoveOperationAsync in class RedissonMap<K,V>
    • scanIterator

      public ScanResult<Map.Entry<Object,Object>> scanIterator(String name, RedisClient client, long startPos, String pattern, int count)
      Overrides:
      scanIterator in class RedissonMap<K,V>
    • scanIteratorAsync

      public RFuture<ScanResult<Map.Entry<Object,Object>>> scanIteratorAsync(String name, RedisClient client, long startPos, String pattern, int count)
      Overrides:
      scanIteratorAsync in class RedissonMap<K,V>
    • fastPutOperationAsync

      protected RFuture<Boolean> fastPutOperationAsync(K key, V value)
      Overrides:
      fastPutOperationAsync in class RedissonMap<K,V>
    • fastPutIfExistsOperationAsync

      protected RFuture<Boolean> fastPutIfExistsOperationAsync(K key, V value)
      Overrides:
      fastPutIfExistsOperationAsync in class RedissonMap<K,V>
    • fastPutIfAbsentOperationAsync

      protected RFuture<Boolean> fastPutIfAbsentOperationAsync(K key, V value)
      Overrides:
      fastPutIfAbsentOperationAsync in class RedissonMap<K,V>
    • fastPutIfAbsent

      public boolean fastPutIfAbsent(K key, V value, long ttl, TimeUnit ttlUnit)
      Description copied from interface: RMapCache
      If the specified key is not already associated with a value, associate it with the given value.

      Stores value mapped by key with specified time to live. Entry expires after specified time to live.

      Works faster than usual RMapCache.putIfAbsent(Object, Object, long, TimeUnit) as it not returns previous value.

      Specified by:
      fastPutIfAbsent in interface RMapCache<K,V>
      Parameters:
      key - - map key
      value - - map value
      ttl - - time to live for key\value entry. If 0 then stores infinitely.
      ttlUnit - - time unit
      Returns:
      true if key is a new key in the hash and value was set. false if key already exists in the hash
    • fastPutIfAbsent

      public boolean fastPutIfAbsent(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit)
      Description copied from interface: RMapCache
      If the specified key is not already associated with a value, associate it with the given value.

      Stores value mapped by key with specified time to live and max idle time. Entry expires when specified time to live or max idle time has expired.

      Works faster than usual RMapCache.putIfAbsent(Object, Object, long, TimeUnit, long, TimeUnit) as it not returns previous value.

      Specified by:
      fastPutIfAbsent in interface RMapCache<K,V>
      Parameters:
      key - - map key
      value - - map value
      ttl - - time to live for key\value entry. If 0 then time to live doesn't affect entry expiration.
      ttlUnit - - time unit
      maxIdleTime - - max idle time for key\value entry. If 0 then max idle time doesn't affect entry expiration.
      maxIdleUnit - - time unit

      if maxIdleTime and ttl params are equal to 0 then entry stores infinitely.

      Returns:
      true if key is a new key in the hash and value was set. false if key already exists in the hash.
    • fastPutIfAbsentAsync

      public RFuture<Boolean> fastPutIfAbsentAsync(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit)
      Description copied from interface: RMapCacheAsync
      If the specified key is not already associated with a value, associate it with the given value.

      Stores value mapped by key with specified time to live and max idle time. Entry expires when specified time to live or max idle time has expired.

      Works faster than usual RMapCacheAsync.putIfAbsentAsync(Object, Object, long, TimeUnit, long, TimeUnit) as it not returns previous value.

      Specified by:
      fastPutIfAbsentAsync in interface RMapCacheAsync<K,V>
      Parameters:
      key - - map key
      value - - map value
      ttl - - time to live for key\value entry. If 0 then time to live doesn't affect entry expiration.
      ttlUnit - - time unit
      maxIdleTime - - max idle time for key\value entry. If 0 then max idle time doesn't affect entry expiration.
      maxIdleUnit - - time unit

      if maxIdleTime and ttl params are equal to 0 then entry stores infinitely.

      Returns:
      true if key is a new key in the hash and value was set. false if key already exists in the hash
    • replaceOperationAsync

      protected RFuture<Boolean> replaceOperationAsync(K key, V oldValue, V newValue)
      Overrides:
      replaceOperationAsync in class RedissonMap<K,V>
    • fastReplaceOperationAsync

      protected RFuture<Boolean> fastReplaceOperationAsync(K key, V value)
      Overrides:
      fastReplaceOperationAsync in class RedissonMap<K,V>
    • replaceOperationAsync

      protected RFuture<V> replaceOperationAsync(K key, V value)
      Overrides:
      replaceOperationAsync in class RedissonMap<K,V>
    • putAllOperationAsync

      protected RFuture<Void> putAllOperationAsync(Map<? extends K,? extends V> map)
      Overrides:
      putAllOperationAsync in class RedissonMap<K,V>
    • addListener

      public int addListener(MapEntryListener listener)
      Description copied from interface: RMapCache
      Adds map entry listener
      Specified by:
      addListener in interface RMapCache<K,V>
      Parameters:
      listener - - entry listener
      Returns:
      listener id
      See Also:
    • addListenerAsync

      public RFuture<Integer> addListenerAsync(MapEntryListener listener)
      Description copied from interface: RMapCacheAsync
      Adds map entry listener
      Specified by:
      addListenerAsync in interface RMapCacheAsync<K,V>
      Parameters:
      listener - - entry listener
      Returns:
      listener id
      See Also:
    • removeListener

      public void removeListener(int listenerId)
      Description copied from interface: RObject
      Removes object event listener
      Specified by:
      removeListener in interface RMapCache<K,V>
      Specified by:
      removeListener in interface RObject
      Overrides:
      removeListener in class RedissonObject
      Parameters:
      listenerId - - listener id
    • sizeInMemoryAsync

      public RFuture<Long> sizeInMemoryAsync()
      Description copied from interface: RObjectAsync
      Returns bytes amount used by object in Redis memory.
      Specified by:
      sizeInMemoryAsync in interface RObjectAsync
      Overrides:
      sizeInMemoryAsync in class RedissonObject
      Returns:
      size in bytes
    • clear

      public void clear()
      Specified by:
      clear in interface Map<K,V>
      Overrides:
      clear in class RedissonMap<K,V>
    • deleteAsync

      public RFuture<Boolean> deleteAsync()
      Description copied from interface: RObjectAsync
      Delete object in async mode
      Specified by:
      deleteAsync in interface RObjectAsync
      Overrides:
      deleteAsync in class RedissonObject
      Returns:
      true if object was deleted false if not
    • expireAsync

      public RFuture<Boolean> expireAsync(long timeToLive, TimeUnit timeUnit, String param, String... keys)
    • expireAtAsync

      protected RFuture<Boolean> expireAtAsync(long timestamp, String param, String... keys)
    • 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 interface RExpirableAsync
      Returns:
      true if the timeout was cleared and false if not
    • readAllKeySetAsync

      public RFuture<Set<K>> readAllKeySetAsync()
      Description copied from interface: RMapAsync
      Read all keys at once
      Specified by:
      readAllKeySetAsync in interface RMapAsync<K,V>
      Overrides:
      readAllKeySetAsync in class RedissonMap<K,V>
      Returns:
      keys
    • randomKeysAsync

      public RFuture<Set<K>> randomKeysAsync(int count)
      Description copied from interface: RMapAsync
      Returns random keys from this map limited by count
      Specified by:
      randomKeysAsync in interface RMapAsync<K,V>
      Overrides:
      randomKeysAsync in class RedissonMap<K,V>
      Parameters:
      count - - keys amount to return
      Returns:
      random keys
    • randomEntriesAsync

      public RFuture<Map<K,V>> randomEntriesAsync(int count)
      Description copied from interface: RMapAsync
      Returns random map entries from this map limited by count
      Specified by:
      randomEntriesAsync in interface RMapAsync<K,V>
      Overrides:
      randomEntriesAsync in class RedissonMap<K,V>
      Parameters:
      count - - entries amount to return
      Returns:
      random entries
    • readAllEntrySetAsync

      public RFuture<Set<Map.Entry<K,V>>> readAllEntrySetAsync()
      Description copied from interface: RMapAsync
      Read all map entries at once
      Specified by:
      readAllEntrySetAsync in interface RMapAsync<K,V>
      Overrides:
      readAllEntrySetAsync in class RedissonMap<K,V>
      Returns:
      entries
    • readAllMapAsync

      public RFuture<Map<K,V>> readAllMapAsync()
      Description copied from interface: RMapAsync
      Read all map as local instance at once
      Specified by:
      readAllMapAsync in interface RMapAsync<K,V>
      Overrides:
      readAllMapAsync in class RedissonMap<K,V>
      Returns:
      map
    • readAllValuesAsync

      public RFuture<Collection<V>> readAllValuesAsync()
      Description copied from interface: RMapAsync
      Read all values at once
      Specified by:
      readAllValuesAsync in interface RMapAsync<K,V>
      Overrides:
      readAllValuesAsync in class RedissonMap<K,V>
      Returns:
      values
    • destroy

      public void destroy()
      Description copied from interface: RDestroyable
      Destroys object when it's not necessary anymore.
      Specified by:
      destroy in interface RDestroyable
      Overrides:
      destroy in class RedissonMap<K,V>
    • expire

      public boolean expire(long timeToLive, TimeUnit timeUnit)
      Description copied from interface: RExpirable
      Specified by:
      expire in interface RExpirable
      Parameters:
      timeToLive - - timeout before object will be deleted
      timeUnit - - timeout time unit
      Returns:
      true if the timeout was set and false if not
    • expireAsync

      public RFuture<Boolean> expireAsync(long timeToLive, TimeUnit timeUnit)
      Description copied from interface: RExpirableAsync
      Specified by:
      expireAsync in interface RExpirableAsync
      Parameters:
      timeToLive - - timeout before object will be deleted
      timeUnit - - timeout time unit
      Returns:
      true if the timeout was set and false if not
    • expireAt

      public boolean expireAt(long timestamp)
      Description copied from interface: RExpirable
      Specified by:
      expireAt in interface RExpirable
      Parameters:
      timestamp - - expire date in milliseconds (Unix timestamp)
      Returns:
      true if the timeout was set and false if not
    • expireAtAsync

      public RFuture<Boolean> expireAtAsync(long timestamp)
      Description copied from interface: RExpirableAsync
      Specified by:
      expireAtAsync in interface RExpirableAsync
      Parameters:
      timestamp - - expire date in milliseconds (Unix timestamp)
      Returns:
      true if the timeout was set and false if not
    • expire

      public boolean expire(Instant instant)
      Description copied from interface: RExpirable
      Sets an expiration date for this object. When expire date comes the key will automatically be deleted.
      Specified by:
      expire in interface RExpirable
      Parameters:
      instant - expire date
      Returns:
      true if the timeout was set and false if not
    • expireIfSet

      public boolean expireIfSet(Instant time)
      Description copied from interface: RExpirable
      Sets an expiration date for this object only if it has been already set. When expire date comes the object will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfSet in interface RExpirable
      Parameters:
      time - expire date
      Returns:
      true if the timeout was set and false if not
    • expireIfSetAsync

      public RFuture<Boolean> expireIfSetAsync(Instant time)
      Description copied from interface: RExpirableAsync
      Sets an expiration date for this object only if it has been already set. When expire date comes the object will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfSetAsync in interface RExpirableAsync
      Parameters:
      time - expire date
      Returns:
      true if the timeout was set and false if not
    • expireIfNotSet

      public boolean expireIfNotSet(Instant time)
      Description copied from interface: RExpirable
      Sets an expiration date for this object only if it hasn't been set before. When expire date comes the object will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfNotSet in interface RExpirable
      Parameters:
      time - expire date
      Returns:
      true if the timeout was set and false if not
    • expireIfNotSetAsync

      public RFuture<Boolean> expireIfNotSetAsync(Instant time)
      Description copied from interface: RExpirableAsync
      Sets an expiration date for this object only if it hasn't been set before. When expire date comes the object will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfNotSetAsync in interface RExpirableAsync
      Parameters:
      time - expire date
      Returns:
      true if the timeout was set and false if not
    • expireIfGreater

      public boolean expireIfGreater(Instant time)
      Description copied from interface: RExpirable
      Sets an expiration date for this object only if it's greater than expiration date set before. When expire date comes the object will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfGreater in interface RExpirable
      Parameters:
      time - expire date
      Returns:
      true if the timeout was set and false if not
    • expireIfGreaterAsync

      public RFuture<Boolean> expireIfGreaterAsync(Instant time)
      Description copied from interface: RExpirableAsync
      Sets an expiration date for this object only if it's greater than expiration date set before. When expire date comes the object will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfGreaterAsync in interface RExpirableAsync
      Parameters:
      time - expire date
      Returns:
      true if the timeout was set and false if not
    • expireIfLess

      public boolean expireIfLess(Instant time)
      Description copied from interface: RExpirable
      Sets an expiration date for this object only if it's less than expiration date set before. When expire date comes the object will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfLess in interface RExpirable
      Parameters:
      time - expire date
      Returns:
      true if the timeout was set and false if not
    • expireIfLessAsync

      public RFuture<Boolean> expireIfLessAsync(Instant time)
      Description copied from interface: RExpirableAsync
      Sets an expiration date for this object only if it's less than expiration date set before. When expire date comes the object will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfLessAsync in interface RExpirableAsync
      Parameters:
      time - expire date
      Returns:
      true if the timeout was set and false if not
    • expireAsync

      public RFuture<Boolean> expireAsync(Instant instant)
      Description copied from interface: RExpirableAsync
      Set an expire date for object. When expire date comes the key will automatically be deleted.
      Specified by:
      expireAsync in interface RExpirableAsync
      Parameters:
      instant - - expire date
      Returns:
      true if the timeout was set and false if not
    • expire

      public boolean expire(Duration duration)
      Description copied from interface: RExpirable
      Sets a timeout for this object. After the timeout has expired, the key will automatically be deleted.
      Specified by:
      expire in interface RExpirable
      Parameters:
      duration - timeout before object will be deleted
      Returns:
      true if the timeout was set and false if not
    • expireAsync

      public RFuture<Boolean> expireAsync(Duration duration)
      Description copied from interface: RExpirableAsync
      Set a timeout for object. After the timeout has expired, the key will automatically be deleted.
      Specified by:
      expireAsync in interface RExpirableAsync
      Parameters:
      duration - timeout before object will be deleted
      Returns:
      true if the timeout was set and false if not
    • expireAt

      public boolean expireAt(Date timestamp)
      Description copied from interface: RExpirable
      Specified by:
      expireAt in interface RExpirable
      Parameters:
      timestamp - - expire date
      Returns:
      true if the timeout was set and false if not
    • expireAtAsync

      public RFuture<Boolean> expireAtAsync(Date timestamp)
      Description copied from interface: RExpirableAsync
      Specified by:
      expireAtAsync in interface RExpirableAsync
      Parameters:
      timestamp - - expire date
      Returns:
      true if the timeout was set and false if not
    • expireIfSet

      public boolean expireIfSet(Duration duration)
      Description copied from interface: RExpirable
      Sets a timeout for this object only if it has been already set. After the timeout has expired, the key will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfSet in interface RExpirable
      Parameters:
      duration - timeout before object will be deleted
      Returns:
      true if the timeout was set and false if not
    • expireIfSetAsync

      public RFuture<Boolean> expireIfSetAsync(Duration duration)
      Description copied from interface: RExpirableAsync
      Sets a timeout for this object only if it has been already set. After the timeout has expired, the key will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfSetAsync in interface RExpirableAsync
      Parameters:
      duration - timeout before object will be deleted
      Returns:
      true if the timeout was set and false if not
    • expireIfNotSet

      public boolean expireIfNotSet(Duration duration)
      Description copied from interface: RExpirable
      Sets a timeout for this object only if it hasn't been set before. After the timeout has expired, the key will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfNotSet in interface RExpirable
      Parameters:
      duration - timeout before object will be deleted
      Returns:
      true if the timeout was set and false if not
    • expireIfNotSetAsync

      public RFuture<Boolean> expireIfNotSetAsync(Duration duration)
      Description copied from interface: RExpirableAsync
      Sets a timeout for this object only if it hasn't been set before. After the timeout has expired, the key will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfNotSetAsync in interface RExpirableAsync
      Parameters:
      duration - timeout before object will be deleted
      Returns:
      true if the timeout was set and false if not
    • expireIfGreater

      public boolean expireIfGreater(Duration duration)
      Description copied from interface: RExpirable
      Sets a timeout for this object only if it's greater than timeout set before. After the timeout has expired, the key will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfGreater in interface RExpirable
      Parameters:
      duration - timeout before object will be deleted
      Returns:
      true if the timeout was set and false if not
    • expireIfGreaterAsync

      public RFuture<Boolean> expireIfGreaterAsync(Duration duration)
      Description copied from interface: RExpirableAsync
      Sets a timeout for this object only if it's greater than timeout set before. After the timeout has expired, the key will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfGreaterAsync in interface RExpirableAsync
      Parameters:
      duration - timeout before object will be deleted
      Returns:
      true if the timeout was set and false if not
    • expireIfLess

      public boolean expireIfLess(Duration duration)
      Description copied from interface: RExpirable
      Sets a timeout for this object only if it's less than timeout set before. After the timeout has expired, the key will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfLess in interface RExpirable
      Parameters:
      duration - timeout before object will be deleted
      Returns:
      true if the timeout was set and false if not
    • expireIfLessAsync

      public RFuture<Boolean> expireIfLessAsync(Duration duration)
      Description copied from interface: RExpirableAsync
      Sets a timeout for this object only if it's less than timeout set before. After the timeout has expired, the key will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfLessAsync in interface RExpirableAsync
      Parameters:
      duration - timeout before object will be deleted
      Returns:
      true if the timeout was set and false if not
    • clearExpire

      public boolean clearExpire()
      Description copied from interface: RExpirable
      Clear an expire timeout or expire date for object.
      Specified by:
      clearExpire in interface RExpirable
      Returns:
      true if timeout was removed false if object does not exist or does not have an associated timeout
    • remainTimeToLive

      public long remainTimeToLive()
      Description copied from interface: RExpirable
      Remaining time to live of Redisson object that has a timeout
      Specified by:
      remainTimeToLive in interface RExpirable
      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 interface RExpirableAsync
      Returns:
      time in milliseconds -2 if the key does not exist. -1 if the key exists but has no associated expire.
    • getExpireTime

      public long getExpireTime()
      Description copied from interface: RExpirable
      Expiration time of Redisson object that has a timeout

      Requires Redis 7.0.0 and higher.

      Specified by:
      getExpireTime in interface RExpirable
      Returns:
      expiration time
    • getExpireTimeAsync

      public RFuture<Long> getExpireTimeAsync()
      Description copied from interface: RExpirableAsync
      Expiration time of Redisson object that has a timeout

      Requires Redis 7.0.0 and higher.

      Specified by:
      getExpireTimeAsync in interface RExpirableAsync
      Returns:
      expiration time
    • clearExpireAsync

      protected RFuture<Boolean> clearExpireAsync(String... keys)