Class Database

java.lang.Object
com.github.darksoulq.abyssallib.common.database.nosql.redis.Database

public class Database extends Object
Manages the connection lifecycle and pooling for a Redis NoSQL database.

This class wraps a JedisPool to provide thread-safe access to Redis and maintains an internal thread pool for executing non-blocking asynchronous commands.

  • Constructor Details

    • Database

      public Database(String host, int port, String password)
      Constructs a new Redis Database handler.
      Parameters:
      host - The server hostname.
      port - The server port.
      password - The server password (can be null or empty for no auth).
  • Method Details

    • connect

      public void connect()
      Initializes the Jedis pool with a maximum of 128 connections.

      Sets a timeout of 2000ms for connection attempts.

    • disconnect

      public void disconnect()
      Gracefully shuts down the Jedis pool and the asynchronous thread pool.
    • getResource

      public redis.clients.jedis.Jedis getResource()
      Borrows a Jedis instance from the pool.

      Note: The returned resource must be closed (returned to pool) after use, typically via a try-with-resources block.

      Returns:
      A Jedis resource.
    • getAsyncPool

      public ExecutorService getAsyncPool()
      Gets the thread pool used for async tasks.
      Returns:
      The ExecutorService instance.
    • executor

      public QueryExecutor executor()
      Creates a new QueryExecutor for performing Redis commands.
      Returns:
      A new QueryExecutor.