Interface RedisDB


public interface RedisDB
Connector for communications to and from the redis server
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    broadcast(overit.geocall.cluster.redis.Message msg, boolean meToo)
    Sends a broadcast message to all listeners who have registered on the current channel.
    void
    del(String key)
    Fast way to delete a single key from redis.
    void
    del(String pattern, String type)
    removes all records whose key matches the pattern passed as input
    <T> T
    execute(Function<redis.clients.jedis.Jedis,T> function)
    Creates a new Jedis connection and pass it as argument to the function parameter that can execute the commands to the redis server.
    get(String key)
    Fast way to get a single string from redis.
    boolean
    Check if the Redis service is available and running
    keys(String pattern, String type)
    Extracts a set of keys from the redis server.
    Normalize the given key by appending a prefix based on the deployment ID.
    void
    onMessage(Consumer<overit.geocall.cluster.redis.Message> listener)
    Records a listener on receipt of a message from the redis server.
    void
    Records a listener on the reconnection event to the redis server.
    void
    set(String key, String value)
    Fast way to set a new string inside redis.
    void
    Close the communication with the redis server.
    void
    Method used to unsubscribe the previous subscription (if any)
    void
    watch(String channel)
    Method used to subscribe to the reception of notifications from a certain channel.
  • Method Details

    • normalizeKey

      String normalizeKey(String key)
      Normalize the given key by appending a prefix based on the deployment ID. If the deployment ID is not available, the prefix "unknown" will be used. The normalized key will have the format "{prefix}:{key}".
      Parameters:
      key - the key to be normalized
      Returns:
      the normalized key
    • stop

      void stop()
      Close the communication with the redis server. After the invocation of this method, no mere connections can be extracted.
    • watch

      void watch(String channel)
      Method used to subscribe to the reception of notifications from a certain channel. The sequent subscription will have no effect; you have to call the unwatch() method before subscribe again to a new channel
      Parameters:
      channel - name of the channel to subscribe to
    • unwatch

      void unwatch()
      Method used to unsubscribe the previous subscription (if any)
    • onReconnect

      void onReconnect(Runnable listener)
      Records a listener on the reconnection event to the redis server. The watch(String) must be called before the registration, otherwise no notification will be received.
      Parameters:
      listener - instance of the listener that will be called on every reconnection.
    • onMessage

      void onMessage(Consumer<overit.geocall.cluster.redis.Message> listener)
      Records a listener on receipt of a message from the redis server. The watch(String) must be called before the registration, otherwise no notification will be received.
      Parameters:
      listener - instance of the listener that will be called on every message.
    • execute

      <T> T execute(Function<redis.clients.jedis.Jedis,T> function)
      Creates a new Jedis connection and pass it as argument to the function parameter that can execute the commands to the redis server. After the function has been called, the connection will be closed.
      Type Parameters:
      T - the function return type
      Parameters:
      function - the function that will be called once the connection has been created
      Returns:
      the function execution result
    • keys

      Set<String> keys(String pattern, String type) throws RedisDBException
      Extracts a set of keys from the redis server. The result set contains only the keys that respect a specific pattern
      Parameters:
      pattern - see MATCH option in the Redis documentation
      type - see TYPE option in the Redis documentation
      Returns:
      a set of the extracted key of an empty set if there's none that matches with the pattern
      Throws:
      RedisDBException - in case of any error during the key extraction
    • del

      void del(String pattern, String type) throws RedisDBException
      removes all records whose key matches the pattern passed as input
      Parameters:
      pattern - see MATCH option in the Redis documentation
      type - see TYPE option in the Redis documentation
      Throws:
      RedisDBException - in case of any error during the removal
    • broadcast

      void broadcast(overit.geocall.cluster.redis.Message msg, boolean meToo) throws RedisDBException
      Sends a broadcast message to all listeners who have registered on the current channel. The watch(String) must be called before use this method.
      Parameters:
      msg - the message that will be send
      meToo - true di the notification must be received by the listeners registered to this connector, false otherwise
      Throws:
      IllegalStateException - if you have not subscribed to any channel
      RedisDBException - in case of any error during the sending
    • set

      void set(String key, String value)
      Fast way to set a new string inside redis. This method is intended for a simple use case that doesn't require to pipeline commands, or set additional parameters like NX, EX ... . To support complex use cases, use the execute(Function) method.
      Parameters:
      key - the reference key
      value - the value that will be set
    • get

      String get(String key)
      Fast way to get a single string from redis. This method is intended for a simple use case that doesn't require to pipeline commands. To support complex use cases, use the execute(Function) method.
      Parameters:
      key - the reference key
      Returns:
      the key value or null if the key doesn't exist
    • del

      void del(String key)
      Fast way to delete a single key from redis. This method is intended for a simple use case that doesn't require to pipeline commands. To support complex use cases, use the execute(Function) method.
      Parameters:
      key - the reference key
    • isReady

      boolean isReady()
      Check if the Redis service is available and running
      Returns:
      true if Redis is up and running; false otherwise