Package io.lettuce.core
Class ClientOptions
- java.lang.Object
-
- io.lettuce.core.ClientOptions
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
ClusterClientOptions
public class ClientOptions extends Object implements Serializable
Client Options to control the behavior ofRedisClient
.- Author:
- Mark Paluch, Gavin Cook, Jim Brunner
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ClientOptions.Builder
Builder forClientOptions
.static class
ClientOptions.DisconnectedBehavior
Behavior of connections in disconnected state.
-
Field Summary
Fields Modifier and Type Field Description static boolean
DEFAULT_AUTO_RECONNECT
static int
DEFAULT_BUFFER_USAGE_RATIO
static boolean
DEFAULT_CANCEL_CMD_RECONNECT_FAIL
static ClientOptions.DisconnectedBehavior
DEFAULT_DISCONNECTED_BEHAVIOR
static boolean
DEFAULT_PING_BEFORE_ACTIVATE_CONNECTION
static ProtocolVersion
DEFAULT_PROTOCOL_VERSION
static boolean
DEFAULT_PUBLISH_ON_SCHEDULER
static ReadOnlyCommands.ReadOnlyPredicate
DEFAULT_READ_ONLY_COMMANDS
static int
DEFAULT_REQUEST_QUEUE_SIZE
static Charset
DEFAULT_SCRIPT_CHARSET
static SocketOptions
DEFAULT_SOCKET_OPTIONS
static SslOptions
DEFAULT_SSL_OPTIONS
static boolean
DEFAULT_SUSPEND_RECONNECT_PROTO_FAIL
static TimeoutOptions
DEFAULT_TIMEOUT_OPTIONS
-
Constructor Summary
Constructors Modifier Constructor Description protected
ClientOptions(ClientOptions original)
protected
ClientOptions(ClientOptions.Builder builder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static ClientOptions.Builder
builder()
Returns a newClientOptions.Builder
to constructClientOptions
.static ClientOptions
copyOf(ClientOptions options)
Create a copy of optionsstatic ClientOptions
create()
Create a new instance ofClientOptions
with default settings.int
getBufferUsageRatio()
Deprecated.since 6.0 in favor ofDecodeBufferPolicy
.ProtocolVersion
getConfiguredProtocolVersion()
Returns the configuredProtocolVersion
.DecodeBufferPolicy
getDecodeBufferPolicy()
Returns theDecodeBufferPolicy
used to reclaim memory.ClientOptions.DisconnectedBehavior
getDisconnectedBehavior()
Behavior for command invocation when connections are in a disconnected state.ProtocolVersion
getProtocolVersion()
Returns theProtocolVersion
to use.ReadOnlyCommands.ReadOnlyPredicate
getReadOnlyCommands()
Predicate to identify commands as read-only.int
getRequestQueueSize()
Request queue size for a connection.Charset
getScriptCharset()
Returns the Lua scriptCharset
.SocketOptions
getSocketOptions()
Returns theSocketOptions
.SslOptions
getSslOptions()
Returns theSslOptions
.TimeoutOptions
getTimeoutOptions()
Returns theTimeoutOptions
.boolean
isAutoReconnect()
Controls auto-reconnect behavior on connections.boolean
isCancelCommandsOnReconnectFailure()
Deprecated.since 6.2, to be removed with 7.0.boolean
isPingBeforeActivateConnection()
Perform a lightweight PING connection handshake when establishing a Redis connection.boolean
isPublishOnScheduler()
Use a dedicatedScheduler
to emit reactive data signals.boolean
isSuspendReconnectOnProtocolFailure()
If this flag istrue
, the reconnect will be suspended on protocol errors.ClientOptions.Builder
mutate()
Returns a builder to create newClientOptions
whose settings are replicated from the currentClientOptions
.
-
-
-
Field Detail
-
DEFAULT_AUTO_RECONNECT
public static final boolean DEFAULT_AUTO_RECONNECT
- See Also:
- Constant Field Values
-
DEFAULT_BUFFER_USAGE_RATIO
public static final int DEFAULT_BUFFER_USAGE_RATIO
- See Also:
- Constant Field Values
-
DEFAULT_CANCEL_CMD_RECONNECT_FAIL
public static final boolean DEFAULT_CANCEL_CMD_RECONNECT_FAIL
- See Also:
- Constant Field Values
-
DEFAULT_DISCONNECTED_BEHAVIOR
public static final ClientOptions.DisconnectedBehavior DEFAULT_DISCONNECTED_BEHAVIOR
-
DEFAULT_PUBLISH_ON_SCHEDULER
public static final boolean DEFAULT_PUBLISH_ON_SCHEDULER
- See Also:
- Constant Field Values
-
DEFAULT_PING_BEFORE_ACTIVATE_CONNECTION
public static final boolean DEFAULT_PING_BEFORE_ACTIVATE_CONNECTION
- See Also:
- Constant Field Values
-
DEFAULT_PROTOCOL_VERSION
public static final ProtocolVersion DEFAULT_PROTOCOL_VERSION
-
DEFAULT_READ_ONLY_COMMANDS
public static final ReadOnlyCommands.ReadOnlyPredicate DEFAULT_READ_ONLY_COMMANDS
-
DEFAULT_REQUEST_QUEUE_SIZE
public static final int DEFAULT_REQUEST_QUEUE_SIZE
- See Also:
- Constant Field Values
-
DEFAULT_SCRIPT_CHARSET
public static final Charset DEFAULT_SCRIPT_CHARSET
-
DEFAULT_SOCKET_OPTIONS
public static final SocketOptions DEFAULT_SOCKET_OPTIONS
-
DEFAULT_SSL_OPTIONS
public static final SslOptions DEFAULT_SSL_OPTIONS
-
DEFAULT_SUSPEND_RECONNECT_PROTO_FAIL
public static final boolean DEFAULT_SUSPEND_RECONNECT_PROTO_FAIL
- See Also:
- Constant Field Values
-
DEFAULT_TIMEOUT_OPTIONS
public static final TimeoutOptions DEFAULT_TIMEOUT_OPTIONS
-
-
Constructor Detail
-
ClientOptions
protected ClientOptions(ClientOptions.Builder builder)
-
ClientOptions
protected ClientOptions(ClientOptions original)
-
-
Method Detail
-
copyOf
public static ClientOptions copyOf(ClientOptions options)
Create a copy of options- Parameters:
options
- the original- Returns:
- A new instance of
ClientOptions
containing the values of options
-
builder
public static ClientOptions.Builder builder()
Returns a newClientOptions.Builder
to constructClientOptions
.- Returns:
- a new
ClientOptions.Builder
to constructClientOptions
.
-
create
public static ClientOptions create()
Create a new instance ofClientOptions
with default settings.- Returns:
- a new instance of
ClientOptions
with default settings
-
mutate
public ClientOptions.Builder mutate()
Returns a builder to create newClientOptions
whose settings are replicated from the currentClientOptions
.- Returns:
- a
ClientOptions.Builder
to create newClientOptions
whose settings are replicated from the currentClientOptions
. - Since:
- 5.1
-
isAutoReconnect
public boolean isAutoReconnect()
Controls auto-reconnect behavior on connections. If auto-reconnect istrue
(default), it is enabled. As soon as a connection gets closed/reset without the intention to close it, the client will try to reconnect and re-issue any queued commands. This flag has also the effect that disconnected connections will refuse commands and cancel these with an exception.- Returns:
true
if auto-reconnect is enabled.
-
isCancelCommandsOnReconnectFailure
@Deprecated public boolean isCancelCommandsOnReconnectFailure()
Deprecated.since 6.2, to be removed with 7.0. SeeClientOptions.Builder.cancelCommandsOnReconnectFailure(boolean)
.If this flag istrue
any queued commands will be canceled when a reconnect fails within the activation sequence. Default isfalse
.- Returns:
true
if commands should be cancelled on reconnect failures.
-
getDecodeBufferPolicy
public DecodeBufferPolicy getDecodeBufferPolicy()
Returns theDecodeBufferPolicy
used to reclaim memory.- Returns:
- the
DecodeBufferPolicy
. - Since:
- 6.0
-
getBufferUsageRatio
@Deprecated public int getBufferUsageRatio()
Deprecated.since 6.0 in favor ofDecodeBufferPolicy
.Buffer usage ratio forCommandHandler
. This ratio controls how often bytes are discarded during decoding. In particular, when buffer usage reachesbufferUsageRatio / bufferUsageRatio + 1
. E.g. settingbufferUsageRatio
to 3, will discard read bytes once the buffer usage reaches 75 percent.- Returns:
- zero.
- Since:
- 5.2
-
getDisconnectedBehavior
public ClientOptions.DisconnectedBehavior getDisconnectedBehavior()
Behavior for command invocation when connections are in a disconnected state. Defaults totrue
. SeeDEFAULT_DISCONNECTED_BEHAVIOR
.- Returns:
- the behavior for command invocation when connections are in a disconnected state
-
getReadOnlyCommands
public ReadOnlyCommands.ReadOnlyPredicate getReadOnlyCommands()
Predicate to identify commands as read-only. Defaults toDEFAULT_READ_ONLY_COMMANDS
.- Returns:
- the predicate to identify read-only commands.
-
getRequestQueueSize
public int getRequestQueueSize()
Request queue size for a connection. This value applies per connection. The command invocation will throw aRedisException
if the queue size is exceeded and a new command is requested. Defaults toInteger.MAX_VALUE
.- Returns:
- the request queue size.
-
isPingBeforeActivateConnection
public boolean isPingBeforeActivateConnection()
Perform a lightweight PING connection handshake when establishing a Redis connection. Iftrue
(default istrue
), every connection and reconnect will issue a PING command and await its response before the connection is activated and enabled for use. If the check fails, the connect/reconnect is treated as a failure. This option has no effect unless forced to use the RESP 2 protocol version. RESP 3/protocol discovery performs aHELLO
handshake.The PING handshake validates whether the other end of the connected socket is a service that behaves like a Redis server.
- Returns:
true
if PING handshake is enabled.
-
getProtocolVersion
public ProtocolVersion getProtocolVersion()
Returns theProtocolVersion
to use.- Returns:
- the
ProtocolVersion
to use.
-
getConfiguredProtocolVersion
public ProtocolVersion getConfiguredProtocolVersion()
Returns the configuredProtocolVersion
. May returnnull
if unconfigured.- Returns:
- the
ProtocolVersion
to use. May benull
. - Since:
- 6.0
-
isPublishOnScheduler
public boolean isPublishOnScheduler()
Use a dedicatedScheduler
to emit reactive data signals. Enabling this option can be useful for reactive sequences that require a significant amount of processing with a single/a few Redis connections.A single Redis connection operates on a single thread. Operations that require a significant amount of processing can lead to a single-threaded-like behavior for all consumers of the Redis connection. When enabled, data signals will be emitted using a different thread served by
ClientResources.eventExecutorGroup()
. Defaults tofalse
, seeDEFAULT_PUBLISH_ON_SCHEDULER
.- Returns:
true
to use a dedicatedScheduler
- Since:
- 5.2
-
isSuspendReconnectOnProtocolFailure
public boolean isSuspendReconnectOnProtocolFailure()
If this flag istrue
, the reconnect will be suspended on protocol errors. Protocol errors are errors while SSL negotiation or when PING before connect fails.- Returns:
true
if reconnect will be suspended on protocol errors.
-
getScriptCharset
public Charset getScriptCharset()
Returns the Lua scriptCharset
.- Returns:
- the script
Charset
. - Since:
- 6.0
-
getSocketOptions
public SocketOptions getSocketOptions()
Returns theSocketOptions
.- Returns:
- the
SocketOptions
.
-
getSslOptions
public SslOptions getSslOptions()
Returns theSslOptions
.- Returns:
- the
SslOptions
.
-
getTimeoutOptions
public TimeoutOptions getTimeoutOptions()
Returns theTimeoutOptions
.- Returns:
- the
TimeoutOptions
. - Since:
- 5.1
-
-