Package io.lettuce.core
Class ClientOptions.Builder
- java.lang.Object
-
- io.lettuce.core.ClientOptions.Builder
-
- Direct Known Subclasses:
ClusterClientOptions.Builder
- Enclosing class:
- ClientOptions
public static class ClientOptions.Builder extends Object
Builder forClientOptions
.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Builder()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ClientOptions.Builder
autoReconnect(boolean autoReconnect)
Enables or disables auto reconnection on connection loss.ClientOptions.Builder
bufferUsageRatio(int bufferUsageRatio)
Deprecated.since 6.0 in favor ofDecodeBufferPolicy
.ClientOptions
build()
Create a new instance ofClientOptions
.ClientOptions.Builder
cancelCommandsOnReconnectFailure(boolean cancelCommandsOnReconnectFailure)
Deprecated.since 6.2, to be removed with 7.0.ClientOptions.Builder
decodeBufferPolicy(DecodeBufferPolicy policy)
Set the policy to discard read bytes from the decoding aggregation buffer to reclaim memory.ClientOptions.Builder
disconnectedBehavior(ClientOptions.DisconnectedBehavior disconnectedBehavior)
Sets the behavior for command invocation when connections are in a disconnected state.ClientOptions.Builder
pingBeforeActivateConnection(boolean pingBeforeActivateConnection)
Perform a lightweight PING connection handshake when establishing a Redis connection.ClientOptions.Builder
protocolVersion(ProtocolVersion protocolVersion)
Sets theProtocolVersion
to use.ClientOptions.Builder
publishOnScheduler(boolean publishOnScheduler)
Use a dedicatedScheduler
to emit reactive data signals.ClientOptions.Builder
readOnlyCommands(ReadOnlyCommands.ReadOnlyPredicate readOnlyCommands)
Identifies commands (e.g.ClientOptions.Builder
requestQueueSize(int requestQueueSize)
Set the per-connection request queue size.ClientOptions.Builder
scriptCharset(Charset scriptCharset)
ClientOptions.Builder
socketOptions(SocketOptions socketOptions)
Sets the low-levelSocketOptions
for the connections kept to Redis servers.ClientOptions.Builder
sslOptions(SslOptions sslOptions)
Sets theSslOptions
for SSL connections kept to Redis servers.ClientOptions.Builder
suspendReconnectOnProtocolFailure(boolean suspendReconnectOnProtocolFailure)
Suspends reconnect when reconnects run into protocol failures (SSL verification, PING before connect fails).ClientOptions.Builder
timeoutOptions(TimeoutOptions timeoutOptions)
Sets theTimeoutOptions
to expire and cancel commands.
-
-
-
Method Detail
-
autoReconnect
public ClientOptions.Builder autoReconnect(boolean autoReconnect)
Enables or disables auto reconnection on connection loss. Defaults totrue
. SeeClientOptions.DEFAULT_AUTO_RECONNECT
.- Parameters:
autoReconnect
- true/false- Returns:
this
-
cancelCommandsOnReconnectFailure
@Deprecated public ClientOptions.Builder cancelCommandsOnReconnectFailure(boolean cancelCommandsOnReconnectFailure)
Deprecated.since 6.2, to be removed with 7.0. This feature is unsafe and may cause protocol offsets if true (i.e. Redis commands are completed with previous command values).Allows cancelling queued commands in case a reconnect fails.Defaults tofalse
. SeeClientOptions.DEFAULT_CANCEL_CMD_RECONNECT_FAIL
. This flag is deprecated and should not be used as it can lead to race conditions and protocol offsets. The reason is that it internally calls reset() which causes a protocol offset. SeeStatefulConnection.reset()
- Parameters:
cancelCommandsOnReconnectFailure
- true/false- Returns:
this
-
bufferUsageRatio
@Deprecated public ClientOptions.Builder bufferUsageRatio(int bufferUsageRatio)
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. SeeClientOptions.DEFAULT_BUFFER_USAGE_RATIO
.- Parameters:
bufferUsageRatio
- the buffer usage ratio. Must be between0
and2^31-1
, typically a value between 1 and 10 representing 50% to 90%.- Returns:
this
- Since:
- 5.2
-
decodeBufferPolicy
public ClientOptions.Builder decodeBufferPolicy(DecodeBufferPolicy policy)
Set the policy to discard read bytes from the decoding aggregation buffer to reclaim memory.- Parameters:
policy
- the policy to use inCommandHandler
- Returns:
this
- Since:
- 6.0
- See Also:
DecodeBufferPolicies
-
disconnectedBehavior
public ClientOptions.Builder disconnectedBehavior(ClientOptions.DisconnectedBehavior disconnectedBehavior)
Sets the behavior for command invocation when connections are in a disconnected state. Defaults totrue
. SeeClientOptions.DEFAULT_DISCONNECTED_BEHAVIOR
.- Parameters:
disconnectedBehavior
- must not benull
.- Returns:
this
-
pingBeforeActivateConnection
public ClientOptions.Builder pingBeforeActivateConnection(boolean pingBeforeActivateConnection)
Perform a lightweight PING connection handshake when establishing a Redis connection. Iftrue
(default istrue
,ClientOptions.DEFAULT_PING_BEFORE_ACTIVATE_CONNECTION
), 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.
- Parameters:
pingBeforeActivateConnection
- true/false- Returns:
this
-
protocolVersion
public ClientOptions.Builder protocolVersion(ProtocolVersion protocolVersion)
Sets theProtocolVersion
to use. Defaults to RESP3. SeeClientOptions.DEFAULT_PROTOCOL_VERSION
.- Parameters:
protocolVersion
- version to use.- Returns:
this
- Since:
- 6.0
- See Also:
ProtocolVersion.newestSupported()
-
publishOnScheduler
public ClientOptions.Builder publishOnScheduler(boolean publishOnScheduler)
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
, seeClientOptions.DEFAULT_PUBLISH_ON_SCHEDULER
.- Parameters:
publishOnScheduler
- true/false- Returns:
this
- Since:
- 5.2
- See Also:
Subscriber.onNext(Object)
,ClientResources.eventExecutorGroup()
-
readOnlyCommands
public ClientOptions.Builder readOnlyCommands(ReadOnlyCommands.ReadOnlyPredicate readOnlyCommands)
Identifies commands (e.g. module commands) as read-only. DefaultsClientOptions.DEFAULT_READ_ONLY_COMMANDS
, seeReadOnlyCommands
.- Parameters:
readOnlyCommands
- must not benull
.- Returns:
this
-
requestQueueSize
public ClientOptions.Builder requestQueueSize(int requestQueueSize)
Set the per-connection request queue size. The command invocation will lead to aRedisException
if the queue size is exceeded. Setting therequestQueueSize
to a lower value will lead earlier to exceptions during overload or while the connection is in a disconnected state. A higher value means hitting the boundary will take longer to occur, but more requests will potentially be queued up and more heap space is used. Defaults toInteger.MAX_VALUE
. SeeClientOptions.DEFAULT_REQUEST_QUEUE_SIZE
.- Parameters:
requestQueueSize
- the queue size.- Returns:
this
-
scriptCharset
public ClientOptions.Builder scriptCharset(Charset scriptCharset)
Sets the Lua scriptCharset
to use to encodescripts
tobyte[]
. Defaults toStandardCharsets.UTF_8
. SeeClientOptions.DEFAULT_SCRIPT_CHARSET
.- Parameters:
scriptCharset
- must not benull
.- Returns:
this
- Since:
- 6.0
-
socketOptions
public ClientOptions.Builder socketOptions(SocketOptions socketOptions)
Sets the low-levelSocketOptions
for the connections kept to Redis servers. SeeClientOptions.DEFAULT_SOCKET_OPTIONS
.- Parameters:
socketOptions
- must not benull
.- Returns:
this
-
sslOptions
public ClientOptions.Builder sslOptions(SslOptions sslOptions)
Sets theSslOptions
for SSL connections kept to Redis servers. SeeClientOptions.DEFAULT_SSL_OPTIONS
.- Parameters:
sslOptions
- must not benull
.- Returns:
this
-
suspendReconnectOnProtocolFailure
public ClientOptions.Builder suspendReconnectOnProtocolFailure(boolean suspendReconnectOnProtocolFailure)
Suspends reconnect when reconnects run into protocol failures (SSL verification, PING before connect fails). Defaults tofalse
. SeeClientOptions.DEFAULT_SUSPEND_RECONNECT_PROTO_FAIL
.- Parameters:
suspendReconnectOnProtocolFailure
- true/false- Returns:
this
-
timeoutOptions
public ClientOptions.Builder timeoutOptions(TimeoutOptions timeoutOptions)
Sets theTimeoutOptions
to expire and cancel commands. SeeClientOptions.DEFAULT_TIMEOUT_OPTIONS
.- Parameters:
timeoutOptions
- must not benull
.- Returns:
this
- Since:
- 5.1
-
build
public ClientOptions build()
Create a new instance ofClientOptions
.- Returns:
- new instance of
ClientOptions
-
-