Class RedisConnectionAbstract

java.lang.Object
com.blackrook.redis.RedisConnectionAbstract
All Implemented Interfaces:
AutoCloseable
Direct Known Subclasses:
RedisConnection, RedisDebugConnection, RedisMonitorConnection, RedisPubSubConnection, RedisServerConnection, RedisUserConnection

public class RedisConnectionAbstract extends Object implements AutoCloseable
A single connection to a Redis server.
Author:
Matthew Tropiano
  • Field Details

    • reader

      protected RESPReader reader
      The input wrapper.
    • writer

      protected RESPWriter writer
      The output wrapper.
  • Constructor Details

    • RedisConnectionAbstract

      public RedisConnectionAbstract() throws IOException
      Creates an open connection to localhost, port 6379, the default Redis port.
      Throws:
      IOException - if an I/O error occurs when creating the socket.
      UnknownHostException - if the IP address of the host could not be determined.
      SecurityException - if a security manager exists and doesn't allow the connection to be made.
    • RedisConnectionAbstract

      public RedisConnectionAbstract(String host, int port) throws IOException
      Creates an open connection.
      Parameters:
      host - the server hostname or address.
      port - the server connection port.
      Throws:
      IOException - if an I/O error occurs when creating the socket.
      UnknownHostException - if the IP address of the host could not be determined.
      SecurityException - if a security manager exists and doesn't allow the connection to be made.
    • RedisConnectionAbstract

      public RedisConnectionAbstract(String host, int port, String password) throws IOException
      Creates an open connection.
      Parameters:
      host - the server hostname or address.
      port - the server connection port.
      password - the server database password.
      Throws:
      IOException - if an I/O error occurs when creating the socket.
      UnknownHostException - if the IP address of the host could not be determined.
      SecurityException - if a security manager exists and doesn't allow the connection to be made.
      RedisException - if the password in the server information is incorrect.
    • RedisConnectionAbstract

      public RedisConnectionAbstract(RedisInfo info) throws IOException
      Creates an open connection.
      Parameters:
      info - the RedisInfo class detailing a connection.
      Throws:
      IOException - if an I/O error occurs when creating the socket.
      UnknownHostException - if the IP address of the host could not be determined.
      SecurityException - if a security manager exists and doesn't allow the connection to be made.
      RedisException - if the password in the server information is incorrect.
  • Method Details

    • reconnect

      public void reconnect() throws IOException
      Reconnects to a server.
      Throws:
      IOException - if an I/O error occurs when creating the socket or the socket is already open.
      UnknownHostException - if the IP address of the host could not be determined.
      SecurityException - if a security manager exists and doesn't allow the connection to be made.
      RedisException - if the password in the server information is incorrect.
    • disconnect

      protected void disconnect()
    • isBound

      public boolean isBound()
      Checks if this connection is successfully bound to an address.
      Returns:
      true if so, false if not.
    • isConnected

      public boolean isConnected()
      Checks if this connection is connected to an endpoint.
      Returns:
      true if so, false if not.
    • isClosed

      public boolean isClosed()
      Checks if this connection is closed.
      Returns:
      true if so, false if not.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable