Class RedisCacher

All Implemented Interfaces:
io.lettuce.core.event.EventBus, MetricConstants, MoleculerLifecycle

public class RedisCacher extends DistributedCacher implements io.lettuce.core.event.EventBus
Redis-based distributed cache. Supports SSL, clustering and password authentication. It's the one of the fastest distributed cache. Supports global and entry-level TTL configuration.

Required dependency:

// https://mvnrepository.com/artifact/biz.paluch.redis/lettuce
compile group: 'biz.paluch.redis', name: 'lettuce', version: '4.5.0.Final'
See Also:
  • Field Details

  • Constructor Details

    • RedisCacher

      public RedisCacher()
    • RedisCacher

      public RedisCacher(String... urls)
    • RedisCacher

      public RedisCacher(String password, int defaultTtl, boolean secure, String... urls)
  • Method Details

    • started

      public void started(ServiceBroker broker) throws Exception
      Initializes cacher instance.
      Specified by:
      started in interface MoleculerLifecycle
      Overrides:
      started in class Cacher
      Parameters:
      broker - parent ServiceBroker
      Throws:
      Exception
    • connect

      protected void connect()
    • disconnect

      protected io.datatree.Promise disconnect()
    • reconnect

      protected void reconnect()
    • stopped

      public void stopped()
      Specified by:
      stopped in interface MoleculerLifecycle
      Overrides:
      stopped in class MoleculerComponent
    • get

      public io.datatree.Promise get(String key)
      Description copied from class: Cacher
      Gets a cached content by a key.
      Specified by:
      get in class Cacher
      Parameters:
      key - cache key
      Returns:
      Promise with cached value (or null, the returned Promise also can be null)
    • set

      public io.datatree.Promise set(String key, io.datatree.Tree value, int ttl)
      Description copied from class: Cacher
      Sets a content by key into the cache.
      Specified by:
      set in class Cacher
      Parameters:
      key - cache key
      value - new value
      ttl - optional TTL of entry (0 == use default TTL)
      Returns:
      Promise with empty value
    • del

      public io.datatree.Promise del(String key)
      Description copied from class: Cacher
      Deletes a content from this cache.
      Specified by:
      del in class Cacher
      Parameters:
      key - cache key
      Returns:
      Promise with empty value
    • clean

      public io.datatree.Promise clean(String match)
      Description copied from class: Cacher
      Cleans this cache. Removes every key by a match string. The default match string is "**".
      Specified by:
      clean in class Cacher
      Parameters:
      match - regex
      Returns:
      Promise with empty value
    • getCacheKeys

      public io.datatree.Promise getCacheKeys()
      Lists all keys of cached entries.
      Specified by:
      getCacheKeys in class Cacher
      Returns:
      a Tree object with a "keys" array.
    • publish

      public void publish(io.lettuce.core.event.Event event)
      Specified by:
      publish in interface io.lettuce.core.event.EventBus
    • get

      public reactor.core.publisher.Flux<io.lettuce.core.event.Event> get()
      Specified by:
      get in interface io.lettuce.core.event.EventBus
    • getUrls

      public String[] getUrls()
    • setUrls

      public void setUrls(String... urls)
    • getPassword

      public String getPassword()
    • setPassword

      public void setPassword(String password)
    • isSecure

      public boolean isSecure()
    • setSecure

      public void setSecure(boolean useSSL)
    • getTtl

      public int getTtl()
    • setTtl

      public void setTtl(int ttl)
    • getSerializer

      public Serializer getSerializer()
    • setSerializer

      public void setSerializer(Serializer serializer)