Package org.redisson

Class RedissonMapCache<K,​V>

    • Method Detail

      • 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).
      • 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.
        Specified by:
        trySetMaxSizeAsync in interface RMapCacheAsync<K,​V>
        Parameters:
        maxSize - - max size
        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. 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).
      • setMaxSizeAsync

        public RFuture<Void> setMaxSizeAsync​(int maxSize)
        Description copied from interface: RMapCacheAsync
        Sets max size of the map. Superfluous elements are evicted using LRU algorithm.
        Specified by:
        setMaxSizeAsync in interface RMapCacheAsync<K,​V>
        Parameters:
        maxSize - - max size
        Returns:
        void
      • 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
      • 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
      • 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: RMapCache
        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 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
        Returns:
        void
      • addAndGet

        public V addAndGet​(K key,
                           Number value)
        Description copied from interface: RMap
        Atomically 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
      • 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)
      • 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)
      • 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.
      • 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
      • removeListener

        public void removeListener​(int listenerId)
        Description copied from interface: RMapCache
        Removes map entry listener
        Specified by:
        removeListener in interface RMapCache<K,​V>
        Parameters:
        listenerId - - listener id
      • 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 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
      • 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 interface RExpirableAsync
        Parameters:
        timestamp - - expire date in milliseconds (Unix timestamp)
        Returns:
        true if the timeout was set and false if not
      • 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
      • destroy

        public void destroy()
        Description copied from interface: RDestroyable
        Destroys object when it's not necessary anymore.
        Specified by:
        destroy in interface RDestroyable
      • 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 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
      • 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 interface RExpirable
        Parameters:
        timestamp - - expire date in milliseconds (Unix timestamp)
        Returns:
        true if the timeout was set and false 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 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
        Set an expire date for object in async mode. When expire date comes the key will automatically be deleted.
        Specified by:
        expireAtAsync in interface RExpirableAsync
        Parameters:
        timestamp - - expire date
        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.