Class JedisWrapper

java.lang.Object
net.ognetwork.ogcore.api.wrappers.JedisWrapper

public class JedisWrapper extends Object
A wrapper for a normal Jedis instance. Provides simplifications and utilities that make working with Jedis for a long time more feasible.
  • Field Details

  • Constructor Details

    • JedisWrapper

      public JedisWrapper(String host, int port, String user, String password)
      Creates an instance of a Jedis Pool with some light wrapper management.
      Parameters:
      host - The host name of the Redis server.
      port - The port of the Redis server.
  • Method Details

    • connect

      public void connect()
      Instantiates the JedisPool. This is called automatically by JedisWrapper(String, int, String, String) and tryReconnect().
    • getPool

      public redis.clients.jedis.JedisPool getPool()
      Gets the Jedis pool.
      Returns:
      the JedisPool instance.
    • runCommand

      public <T> T runCommand(JedisCommand<T> command)
      Runs a command with an instance from the Jedis pool.
      Type Parameters:
      T - Any generic type. This would be the type that is returnd by the JedisCommand.
      Parameters:
      command - the command of type JedisCommand.
      Returns:
      The result of the JedisCommand run function.
    • isConnected

      public boolean isConnected()
      Checks if the Jedis pool is connected.
      Returns:
      true if the jedis pool is connected, otherwise false.
    • tryReconnect

      public boolean tryReconnect()
      Attempts to reconnect the Jedis pool. If the connection is strong, this will not do anything. If the connection is broken, this will reconnect.
      Returns:
      true if the connection was re-established, false if the connection did not need to be reconnected.
    • getInstance

      public static JedisWrapper getInstance()