Class RedisConnectionPool
java.lang.Object
com.blackrook.redis.RedisConnectionPool
A connection pool for Redis socket connections.
Connections are fair - released connections are added to the end of an "available" queue.
- Author:
- Matthew Tropiano
-
Constructor Summary
ConstructorsConstructorDescriptionRedisConnectionPool(int connectionCount, RedisInfo info) Creates a connection pool using a connection to a host.RedisConnectionPool(int connections, String host, int port, String password) Creates a connection pool using a connection to a host. -
Method Summary
Modifier and TypeMethodDescriptionRetrieves an available connection from the pool.getAvailableConnection(long waitMillis) Retrieves an available connection from the pool.intintvoidreleaseConnection(RedisConnection connection) Releases a Redis connection back to this pool.
-
Constructor Details
-
RedisConnectionPool
public RedisConnectionPool(int connections, String host, int port, String password) throws IOException Creates a connection pool using a connection to a host.- Parameters:
connections- the number of connections to open.host- the host to connect to.port- the port to connect to on the host.password- the Redis DB password.- Throws:
IOException- if a connection can't be made.UnknownHostException- if the server host can't be resolved.
-
RedisConnectionPool
Creates a connection pool using a connection to a host.- Parameters:
connectionCount- the number of connections to open.info- theRedisInfoobject to use to describe DB information.- Throws:
IOException- if a connection can't be made.UnknownHostException- if the server host can't be resolved.
-
-
Method Details
-
getAvailableConnection
Retrieves an available connection from the pool.- Returns:
- an available connection.
- Throws:
InterruptedException- if an interrupt is thrown by the current thread waiting for an available connection.IOException- if a connection cannot be re-created or re-established.
-
getAvailableConnection
public RedisConnection getAvailableConnection(long waitMillis) throws InterruptedException, TimeoutException, IOException Retrieves an available connection from the pool.- Parameters:
waitMillis- the amount of time (in milliseconds) to wait for a connection.- Returns:
- an available connection.
- Throws:
InterruptedException- if an interrupt is thrown by the current thread waiting for an available connection.TimeoutException- if the wait lapses and there are no available connections.IOException- if a connection cannot be re-created or re-established.
-
releaseConnection
Releases a Redis connection back to this pool.- Parameters:
connection- the connection to release.- Throws:
IllegalStateException- if the connection was never maintained by this pool.
-
getAvailableConnectionCount
public int getAvailableConnectionCount()- Returns:
- the amount of available connections.
-
getUsedConnectionCount
public int getUsedConnectionCount()- Returns:
- the amount of used connections.
-