Interface RSetCache<V>

Type Parameters:
V - value
All Superinterfaces:
Collection<V>, Iterable<V>, RCollectionAsync<V>, RDestroyable, RExpirable, RExpirableAsync, RObject, RObjectAsync, RSet<V>, RSetAsync<V>, RSetCacheAsync<V>, RSortable<Set<V>>, RSortableAsync<Set<V>>, Set<V>
All Known Implementing Classes:
RedissonSetCache, RedissonTransactionalSetCache

public interface RSetCache<V> extends RSet<V>, RExpirable, RSetCacheAsync<V>, RDestroyable

Set-based cache with ability to set TTL for each object.

Current Redis implementation doesn't have set entry eviction functionality. Thus values are checked for TTL expiration during any value read operation. If entry expired then it doesn't returns and clean task runs asynchronous. Clean task deletes removes 100 expired entries at once. In addition there is EvictionScheduler. This scheduler deletes expired entries in time interval between 5 seconds to 2 hours.

If eviction is not required then it's better to use RSet.

Author:
Nikita Koksharov
  • Method Details

    • add

      boolean add(V value, long ttl, TimeUnit unit)
      Stores value with specified time to live. Value expires after specified time to live.
      Parameters:
      value - to add
      ttl - - time to live for key\value entry. If 0 then stores infinitely.
      unit - - time unit
      Returns:
      true if value has been added. false if value already been in collection.
    • size

      int size()
      Returns the number of elements in cache. This number can reflects expired elements too due to non realtime cleanup process.
      Specified by:
      size in interface Collection<V>
      Specified by:
      size in interface Set<V>
      Returns:
      size of set
    • tryAdd

      @Deprecated boolean tryAdd(long ttl, TimeUnit unit, V... values)
      Deprecated.
      Parameters:
      ttl - - time to live for value. If 0 then stores infinitely.
      unit - - time unit
      values - - values to add
      Returns:
      true if elements successfully added, otherwise false.
    • addIfAbsent

      boolean addIfAbsent(Duration ttl, V object)
      Adds element to this set only if has not been added before.

      Requires Redis 3.0.2 and higher.

      Parameters:
      ttl - - object ttl
      object - - object itself
      Returns:
      true if element added and false if not.
    • addIfExists

      boolean addIfExists(Duration ttl, V object)
      Adds element to this set only if it's already exists.

      Requires Redis 3.0.2 and higher.

      Parameters:
      ttl - - object ttl
      object - - object itself
      Returns:
      true if element added and false if not.
    • addIfLess

      boolean addIfLess(Duration ttl, V object)
      Adds element to this set only if new ttl less than current ttl of existed element.

      Requires Redis 6.2.0 and higher.

      Parameters:
      ttl - - object ttl
      object - - object itself
      Returns:
      true if element added and false if not.
    • addIfGreater

      boolean addIfGreater(Duration ttl, V object)
      Adds element to this set only if new ttl greater than current ttl of existed element.

      Requires Redis 6.2.0 and higher.

      Parameters:
      ttl - - object ttl
      object - - object itself
      Returns:
      true if element added and false if not.
    • addAll

      int addAll(Map<V,Duration> objects)
      Adds all elements contained in the specified map to this sorted set. Map contains of ttl mapped by object.
      Parameters:
      objects - - map of elements to add
      Returns:
      amount of added elements, not including already existing in this sorted set
    • addAllIfAbsent

      int addAllIfAbsent(Map<V,Duration> objects)
      Adds elements to this set only if they haven't been added before.

      Requires Redis 3.0.2 and higher.

      Parameters:
      objects - map of elements to add
      Returns:
      amount of added elements
    • addAllIfExist

      int addAllIfExist(Map<V,Duration> objects)
      Adds elements to this set only if they already exist.

      Requires Redis 3.0.2 and higher.

      Parameters:
      objects - map of elements to add
      Returns:
      amount of added elements
    • addAllIfGreater

      int addAllIfGreater(Map<V,Duration> objects)
      Adds elements to this set only if new ttl greater than current ttl of existed elements.

      Requires Redis 6.2.0 and higher.

      Parameters:
      objects - map of elements to add
      Returns:
      amount of added elements
    • addAllIfLess

      int addAllIfLess(Map<V,Duration> objects)
      Adds elements to this set only if new ttl less than current ttl of existed elements.

      Requires Redis 6.2.0 and higher.

      Parameters:
      objects - map of elements to add
      Returns:
      amount of added elements