Package com.blackrook.redis
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 Summary
Fields Modifier and Type Field Description protected RESPReaderreaderThe input wrapper.protected RESPWriterwriterThe output wrapper.
-
Constructor Summary
Constructors Constructor Description RedisConnectionAbstract()Creates an open connection to localhost, port 6379, the default Redis port.RedisConnectionAbstract(RedisInfo info)Creates an open connection.RedisConnectionAbstract(String host, int port)Creates an open connection.RedisConnectionAbstract(String host, int port, String password)Creates an open connection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()protected voiddisconnect()booleanisBound()Checks if this connection is successfully bound to an address.booleanisClosed()Checks if this connection is closed.booleanisConnected()Checks if this connection is connected to an endpoint.voidreconnect()Reconnects to a server.
-
-
-
Field Detail
-
reader
protected RESPReader reader
The input wrapper.
-
writer
protected RESPWriter writer
The output wrapper.
-
-
Constructor Detail
-
RedisConnectionAbstract
public RedisConnectionAbstract() throws IOExceptionCreates 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- theRedisInfoclass 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 Detail
-
reconnect
public void reconnect() throws IOExceptionReconnects 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:
closein interfaceAutoCloseable
-
-