Package io.lettuce.core.cluster
Class ClusterClientOptions.Builder
- java.lang.Object
-
- io.lettuce.core.ClientOptions.Builder
-
- io.lettuce.core.cluster.ClusterClientOptions.Builder
-
- Enclosing class:
- ClusterClientOptions
public static class ClusterClientOptions.Builder extends ClientOptions.Builder
Builder forClusterClientOptions
.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Builder()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ClusterClientOptions.Builder
autoReconnect(boolean autoReconnect)
Enables or disables auto reconnection on connection loss.ClusterClientOptions.Builder
bufferUsageRatio(int bufferUsageRatio)
Deprecated.since 6.0 in favor ofDecodeBufferPolicy
.ClusterClientOptions
build()
Create a new instance ofClusterClientOptions
ClusterClientOptions.Builder
cancelCommandsOnReconnectFailure(boolean cancelCommandsOnReconnectFailure)
Deprecated.since 6.2, to be removed with 7.0.ClusterClientOptions.Builder
decodeBufferPolicy(DecodeBufferPolicy decodeBufferPolicy)
Set the policy to discard read bytes from the decoding aggregation buffer to reclaim memory.ClusterClientOptions.Builder
disconnectedBehavior(ClientOptions.DisconnectedBehavior disconnectedBehavior)
Sets the behavior for command invocation when connections are in a disconnected state.ClusterClientOptions.Builder
maxRedirects(int maxRedirects)
Number of maximal cluster redirects (-MOVED and -ASK) to follow in case a key was moved from one node to another node.ClusterClientOptions.Builder
nodeFilter(Predicate<RedisClusterNode> nodeFilter)
Provide anode filter
to filter cluster nodes fromPartitions
.ClusterClientOptions.Builder
pingBeforeActivateConnection(boolean pingBeforeActivateConnection)
Perform a lightweight PING connection handshake when establishing a Redis connection.ClusterClientOptions.Builder
protocolVersion(ProtocolVersion protocolVersion)
Sets theProtocolVersion
to use.ClusterClientOptions.Builder
publishOnScheduler(boolean publishOnScheduler)
Use a dedicatedScheduler
to emit reactive data signals.ClusterClientOptions.Builder
readOnlyCommands(ReadOnlyCommands.ReadOnlyPredicate readOnlyCommands)
Identifies commands (e.g.ClusterClientOptions.Builder
requestQueueSize(int requestQueueSize)
Set the per-connection request queue size.ClusterClientOptions.Builder
scriptCharset(Charset scriptCharset)
ClusterClientOptions.Builder
socketOptions(SocketOptions socketOptions)
Sets the low-levelSocketOptions
for the connections kept to Redis servers.ClusterClientOptions.Builder
sslOptions(SslOptions sslOptions)
Sets theSslOptions
for SSL connections kept to Redis servers.ClusterClientOptions.Builder
suspendReconnectOnProtocolFailure(boolean suspendReconnectOnProtocolFailure)
Suspends reconnect when reconnects run into protocol failures (SSL verification, PING before connect fails).ClusterClientOptions.Builder
timeoutOptions(TimeoutOptions timeoutOptions)
Sets theTimeoutOptions
to expire and cancel commands.ClusterClientOptions.Builder
topologyRefreshOptions(ClusterTopologyRefreshOptions topologyRefreshOptions)
Sets theClusterTopologyRefreshOptions
for detailed control of topology updates.ClusterClientOptions.Builder
validateClusterNodeMembership(boolean validateClusterNodeMembership)
Validate the cluster node membership before allowing connections to a cluster node.
-
-
-
Method Detail
-
autoReconnect
public ClusterClientOptions.Builder autoReconnect(boolean autoReconnect)
Description copied from class:ClientOptions.Builder
Enables or disables auto reconnection on connection loss. Defaults totrue
. SeeClientOptions.DEFAULT_AUTO_RECONNECT
.- Overrides:
autoReconnect
in classClientOptions.Builder
- Parameters:
autoReconnect
- true/false- Returns:
this
-
bufferUsageRatio
@Deprecated public ClusterClientOptions.Builder bufferUsageRatio(int bufferUsageRatio)
Deprecated.since 6.0 in favor ofDecodeBufferPolicy
.Description copied from class:ClientOptions.Builder
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
.- Overrides:
bufferUsageRatio
in classClientOptions.Builder
- 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
-
cancelCommandsOnReconnectFailure
@Deprecated public ClusterClientOptions.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).Description copied from class:ClientOptions.Builder
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()
- Overrides:
cancelCommandsOnReconnectFailure
in classClientOptions.Builder
- Parameters:
cancelCommandsOnReconnectFailure
- true/false- Returns:
-
decodeBufferPolicy
public ClusterClientOptions.Builder decodeBufferPolicy(DecodeBufferPolicy decodeBufferPolicy)
Description copied from class:ClientOptions.Builder
Set the policy to discard read bytes from the decoding aggregation buffer to reclaim memory.- Overrides:
decodeBufferPolicy
in classClientOptions.Builder
- Parameters:
decodeBufferPolicy
- the policy to use inCommandHandler
- Returns:
this
- See Also:
DecodeBufferPolicies
-
disconnectedBehavior
public ClusterClientOptions.Builder disconnectedBehavior(ClientOptions.DisconnectedBehavior disconnectedBehavior)
Description copied from class:ClientOptions.Builder
Sets the behavior for command invocation when connections are in a disconnected state. Defaults totrue
. SeeClientOptions.DEFAULT_DISCONNECTED_BEHAVIOR
.- Overrides:
disconnectedBehavior
in classClientOptions.Builder
- Parameters:
disconnectedBehavior
- must not benull
.- Returns:
this
-
maxRedirects
public ClusterClientOptions.Builder maxRedirects(int maxRedirects)
Number of maximal cluster redirects (-MOVED and -ASK) to follow in case a key was moved from one node to another node. Defaults to 5. SeeClusterClientOptions.DEFAULT_MAX_REDIRECTS
.- Parameters:
maxRedirects
- the limit of maximal cluster redirects- Returns:
this
-
pingBeforeActivateConnection
public ClusterClientOptions.Builder pingBeforeActivateConnection(boolean pingBeforeActivateConnection)
Description copied from class:ClientOptions.Builder
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.
- Overrides:
pingBeforeActivateConnection
in classClientOptions.Builder
- Parameters:
pingBeforeActivateConnection
- true/false- Returns:
this
-
protocolVersion
public ClusterClientOptions.Builder protocolVersion(ProtocolVersion protocolVersion)
Description copied from class:ClientOptions.Builder
Sets theProtocolVersion
to use. Defaults to RESP3. SeeClientOptions.DEFAULT_PROTOCOL_VERSION
.- Overrides:
protocolVersion
in classClientOptions.Builder
- Parameters:
protocolVersion
- version to use.- Returns:
this
- See Also:
ProtocolVersion.newestSupported()
-
suspendReconnectOnProtocolFailure
public ClusterClientOptions.Builder suspendReconnectOnProtocolFailure(boolean suspendReconnectOnProtocolFailure)
Description copied from class:ClientOptions.Builder
Suspends reconnect when reconnects run into protocol failures (SSL verification, PING before connect fails). Defaults tofalse
. SeeClientOptions.DEFAULT_SUSPEND_RECONNECT_PROTO_FAIL
.- Overrides:
suspendReconnectOnProtocolFailure
in classClientOptions.Builder
- Parameters:
suspendReconnectOnProtocolFailure
- true/false- Returns:
this
-
publishOnScheduler
public ClusterClientOptions.Builder publishOnScheduler(boolean publishOnScheduler)
Description copied from class:ClientOptions.Builder
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
.- Overrides:
publishOnScheduler
in classClientOptions.Builder
- Parameters:
publishOnScheduler
- true/false- Returns:
this
- See Also:
Subscriber.onNext(Object)
,ClientResources.eventExecutorGroup()
-
readOnlyCommands
public ClusterClientOptions.Builder readOnlyCommands(ReadOnlyCommands.ReadOnlyPredicate readOnlyCommands)
Description copied from class:ClientOptions.Builder
Identifies commands (e.g. module commands) as read-only. DefaultsClientOptions.DEFAULT_READ_ONLY_COMMANDS
, seeReadOnlyCommands
.- Overrides:
readOnlyCommands
in classClientOptions.Builder
- Parameters:
readOnlyCommands
- must not benull
.- Returns:
this
-
requestQueueSize
public ClusterClientOptions.Builder requestQueueSize(int requestQueueSize)
Description copied from class:ClientOptions.Builder
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
.- Overrides:
requestQueueSize
in classClientOptions.Builder
- Parameters:
requestQueueSize
- the queue size.- Returns:
this
-
scriptCharset
public ClusterClientOptions.Builder scriptCharset(Charset scriptCharset)
Description copied from class:ClientOptions.Builder
Sets the Lua scriptCharset
to use to encodescripts
tobyte[]
. Defaults toStandardCharsets.UTF_8
. SeeClientOptions.DEFAULT_SCRIPT_CHARSET
.- Overrides:
scriptCharset
in classClientOptions.Builder
- Parameters:
scriptCharset
- must not benull
.- Returns:
this
-
socketOptions
public ClusterClientOptions.Builder socketOptions(SocketOptions socketOptions)
Description copied from class:ClientOptions.Builder
Sets the low-levelSocketOptions
for the connections kept to Redis servers. SeeClientOptions.DEFAULT_SOCKET_OPTIONS
.- Overrides:
socketOptions
in classClientOptions.Builder
- Parameters:
socketOptions
- must not benull
.- Returns:
this
-
sslOptions
public ClusterClientOptions.Builder sslOptions(SslOptions sslOptions)
Description copied from class:ClientOptions.Builder
Sets theSslOptions
for SSL connections kept to Redis servers. SeeClientOptions.DEFAULT_SSL_OPTIONS
.- Overrides:
sslOptions
in classClientOptions.Builder
- Parameters:
sslOptions
- must not benull
.- Returns:
this
-
timeoutOptions
public ClusterClientOptions.Builder timeoutOptions(TimeoutOptions timeoutOptions)
Description copied from class:ClientOptions.Builder
Sets theTimeoutOptions
to expire and cancel commands. SeeClientOptions.DEFAULT_TIMEOUT_OPTIONS
.- Overrides:
timeoutOptions
in classClientOptions.Builder
- Parameters:
timeoutOptions
- must not benull
.- Returns:
this
-
topologyRefreshOptions
public ClusterClientOptions.Builder topologyRefreshOptions(ClusterTopologyRefreshOptions topologyRefreshOptions)
Sets theClusterTopologyRefreshOptions
for detailed control of topology updates.- Parameters:
topologyRefreshOptions
- theClusterTopologyRefreshOptions
- Returns:
this
-
validateClusterNodeMembership
public ClusterClientOptions.Builder validateClusterNodeMembership(boolean validateClusterNodeMembership)
Validate the cluster node membership before allowing connections to a cluster node. Defaults totrue
. SeeClusterClientOptions.DEFAULT_VALIDATE_CLUSTER_MEMBERSHIP
.- Parameters:
validateClusterNodeMembership
-true
if validation is enabled.- Returns:
this
-
nodeFilter
public ClusterClientOptions.Builder nodeFilter(Predicate<RedisClusterNode> nodeFilter)
Provide anode filter
to filter cluster nodes fromPartitions
.- Parameters:
nodeFilter
- must not benull
.- Returns:
this
- Since:
- 6.1.6
-
build
public ClusterClientOptions build()
Create a new instance ofClusterClientOptions
- Overrides:
build
in classClientOptions.Builder
- Returns:
- new instance of
ClusterClientOptions
-
-