Class Database
java.lang.Object
com.github.darksoulq.abyssallib.common.database.nosql.redis.Database
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidconnect()Initializes the Jedis pool with a maximum of 128 connections.voidGracefully shuts down the Jedis pool and the asynchronous thread pool.executor()Creates a new QueryExecutor for performing Redis commands.Gets the thread pool used for async tasks.redis.clients.jedis.JedisBorrows a Jedis instance from the pool.
-
Constructor Details
-
Database
-
-
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
Jedisresource.
-
getAsyncPool
Gets the thread pool used for async tasks.- Returns:
- The
ExecutorServiceinstance.
-
executor
Creates a new QueryExecutor for performing Redis commands.- Returns:
- A new
QueryExecutor.
-