Class RedisConnectionPool


  • public class RedisConnectionPool
    extends Object
    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 Detail

      • 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

        public RedisConnectionPool​(int connectionCount,
                                   RedisInfo info)
                            throws IOException
        Creates a connection pool using a connection to a host.
        Parameters:
        connectionCount - the number of connections to open.
        info - the RedisInfo object 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 Detail

      • 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

        public void releaseConnection​(RedisConnection connection)
        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.