public interface Connection
Connection
defines the general (required) and optional
contract of a JRedis connection.
Redis protocol does not provide for request sequencing (for a
variety of good reasons) and guaranteed delivery semantics are
supported only by multi-exec (redis transaction) protocol. Accordingly,
Connection
is not required (given that it can not) to support
fault-tolerant semantics.
If a connection faults during an interaction with the server (e.g. anytime during send and receive) it must raise one of the following:
ConnectionReset
- connection faulted but connection re-established
ConnectionFault
- connection faulted and reconnect not possible.
In either case, it should be noted that there exists a tiny (but possible) window where even with append logging on the server, where the server received and processed the request but never could reply (e.g. the server crashes for whatever reason). These considerations are irrelevant to read only commands, but are significant in context of write ops (e.g. INCR). If you require guarantees on writes, you must use redis transactions (e.g. multi-bulk).
That said, the Connection
's optional event and state management
do provide sufficient support for a softer set of guarantees for
transparent connection management (on fault detection, connect on demand,
etc.).
Modifier and Type | Interface and Description |
---|---|
static class |
Connection.Event
Events raised by the
Connection . |
static interface |
Connection.Factory |
static class |
Connection.Flag
Connection flags - not necessarily mutually exclusive.
|
static interface |
Connection.Listener
Connection listeners' callback API. |
static class |
Connection.Modality
Enum for defining the operational modality of the protocol handlers.
|
static class |
Connection.Property
Enumeration of the top-level properties of the
Connection that can be
specified by the User. |
static interface |
Connection.Socket |
static class |
Connection.State |
Modifier and Type | Method and Description |
---|---|
boolean |
addListener(Connection.Listener connListener)
Connection.Event propagation.
|
ConnectionSpec |
getSpec()
The
ConnectionSpec of a Connection must be invariant during its life-cycle. |
Future<Response> |
queueRequest(Command cmd,
byte[]... args)
A non-blocking call to service the specified request at some point in the future.
|
boolean |
removeListener(Connection.Listener connListener)
Optional event propagation method.
|
Response |
serviceRequest(Command cmd,
byte[]... args)
A blocking call to service the specified request.
|
ConnectionSpec getSpec()
ConnectionSpec
of a Connection must be invariant during its life-cycle.ConnectionSpec
for this Connection.Response serviceRequest(Command cmd, byte[]... args) throws RedisException, ClientRuntimeException, ProviderException
Protocol
interface
and can (and should) be addressed at the implementation level (for example when creating
handler instances using a specification set, including max wait for synchronous response.)
Connection.Modality.Asynchronous
handlers must always throw a ClientRuntimeException
for this method which violates the contract for Connection.Modality.Asynchronous
handlers.
cmd
- args
- RedisException
ClientRuntimeException
ProviderException
Future<Response> queueRequest(Command cmd, byte[]... args) throws ClientRuntimeException, ProviderException
Future
object of parametric type Response
When the request is serviced, call to Future.get()
will return the request response.
Connection.Modality.Synchronous
handlers must always throw a ClientRuntimeException
for this method which violates the contract for Connection.Modality.Synchronous
handlers.
If request resulted in a redis error (RedisException
), the exception will be set as the cause of
the corresponding ExecutionException
of the Future
object returned.
cmd
- args
- Future
Response
.ClientRuntimeException
ProviderException
Future
,
ExecutionException
boolean addListener(Connection.Listener connListener)
connListener
- boolean removeListener(Connection.Listener connListener)
Connection.Listener
s.connListener
- Copyright © 2009–2015. All rights reserved.