public class RedisOptions extends Object
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_ENDPOINT
The default Redis endpoint:
redis://localhost:6379 |
Constructor and Description |
---|
RedisOptions()
Creates a default configuration object using redis server defaults
|
RedisOptions(JsonObject json)
Copy from JSON constructor.
|
RedisOptions(RedisOptions other)
Copy constructor.
|
Modifier and Type | Method and Description |
---|---|
RedisOptions |
addConnectionString(String connectionString)
Adds a connection string (endpoint) to use while connecting to the redis server.
|
RedisOptions |
addEndpoint(String connectionString)
Deprecated.
see
setConnectionString(String connectionString) for a better naming |
String |
getEndpoint()
Gets the redis endpoint to use
|
List<String> |
getEndpoints()
Gets the list of redis endpoints to use (mostly used while connecting to a cluster)
|
long |
getHashSlotCacheTTL()
Returns the TTL of the hash slot cache.
|
String |
getMasterName()
Get the name of the master set.
|
int |
getMaxNestedArrays()
Tune how much nested arrays are allowed on a redis response.
|
int |
getMaxPoolSize()
Get the maximum size of the connection pool.
|
int |
getMaxPoolWaiting()
Get the maximum number of requests waiting for a connection from the pool.
|
int |
getMaxWaitingHandlers()
The client will always work on pipeline mode, this means that messages can start queueing.
|
String |
getMetricsName() |
NetClientOptions |
getNetClientOptions()
Get the net client options used to connect to the server.
|
String |
getPassword()
Get the default password for cluster/sentinel connections, if not set it will try to
extract it from the current default endpoint.
|
int |
getPoolCleanerInterval()
Get how often the connection pool will be cleaned.
|
String |
getPoolName()
Get the connection pool name to be used for metrics reporting.
|
PoolOptions |
getPoolOptions() |
int |
getPoolRecycleTimeout()
Get how long a connection can stay unused before it is recycled during connection pool
cleaning.
|
ProtocolVersion |
getPreferredProtocolVersion()
Returns the preferred protocol version to be used during protocol negotiation.
|
RedisRole |
getRole()
Get the client role; that is, to which kind of node should the connection be established.
|
RedisTopology |
getTopology()
Get how the topology should be obtained.
|
TracingPolicy |
getTracingPolicy() |
RedisClientType |
getType()
Get the type of client to be created.
|
RedisReplicas |
getUseReplicas()
Get whether to use replica nodes for read only queries.
|
boolean |
isAutoFailover()
Returns whether automatic failover is enabled.
|
boolean |
isProtocolNegotiation()
Should the client perform
RESP protocol negotiation during the connection handshake. |
RedisOptions |
setAutoFailover(boolean autoFailover)
Returns whether automatic failover is enabled.
|
RedisOptions |
setConnectionString(String connectionString)
Sets a single connection string (endpoint) to use while connecting to the redis server.
|
RedisOptions |
setEndpoint(String connectionString)
Deprecated.
see
setConnectionString(String connectionString) for a better naming |
RedisOptions |
setEndpoints(List<String> endpoints)
Set the endpoints to use while connecting to the redis server.
|
RedisOptions |
setHashSlotCacheTTL(long hashSlotCacheTTL)
Sets the TTL of the hash slot cache.
|
RedisOptions |
setMasterName(String masterName)
Set the name of the master set.
|
RedisOptions |
setMaxNestedArrays(int maxNestedArrays)
Tune how much nested arrays are allowed on a redis response.
|
RedisOptions |
setMaxPoolSize(int maxPoolSize)
Set the maximum size of the connection pool.
|
RedisOptions |
setMaxPoolWaiting(int maxPoolWaiting)
Set the maximum number of requests waiting for a connection from the pool.
|
RedisOptions |
setMaxWaitingHandlers(int maxWaitingHandlers)
The client will always work on pipeline mode, this means that messages can start queueing.
|
RedisOptions |
setMetricsName(String metricsName)
Set the metrics name identifying the reported metrics, useful for grouping metrics
with the same name.
|
RedisOptions |
setNetClientOptions(NetClientOptions netClientOptions)
Set the net client options to be used while connecting to the redis server.
|
RedisOptions |
setPassword(String password)
Set the default password for cluster/sentinel connections.
|
RedisOptions |
setPoolCleanerInterval(int poolCleanerInterval)
Set how often the connection pool will be cleaned.
|
RedisOptions |
setPoolName(String poolName)
Set the connection pool name to be used for metrics reporting.
|
RedisOptions |
setPoolRecycleTimeout(int poolRecycleTimeout)
Set how long a connection can stay unused before it is recycled during connection pool
cleaning.
|
RedisOptions |
setPreferredProtocolVersion(ProtocolVersion preferredProtocolVersion)
Sets the preferred protocol version to be used during protocol negotiation.
|
RedisOptions |
setProtocolNegotiation(boolean protocolNegotiation)
Should the client perform
REST protocol negotiation during the connection acquire. |
RedisOptions |
setRole(RedisRole role)
Set the client role; that is, to which kind of node should the connection be established.
|
RedisOptions |
setTopology(RedisTopology topology)
Set how the topology should be obtained.
|
RedisOptions |
setTracingPolicy(TracingPolicy tracingPolicy)
Set the tracing policy for the client behavior when Vert.x has tracing enabled.
|
RedisOptions |
setType(RedisClientType type)
Set the desired client type to be created.
|
RedisOptions |
setUseReplicas(RedisReplicas useReplicas)
Set whether to use replica nodes for read only queries.
|
JsonObject |
toJson()
Converts this object to JSON notation.
|
public static final String DEFAULT_ENDPOINT
redis://localhost:6379
public RedisOptions()
public RedisOptions(RedisOptions other)
other
- the object to clone.public RedisOptions(JsonObject json)
json
- source jsonpublic RedisClientType getType()
public RedisOptions setType(RedisClientType type)
type
- the client type.public NetClientOptions getNetClientOptions()
public RedisOptions setNetClientOptions(NetClientOptions netClientOptions)
netClientOptions
- custom net client options.public List<String> getEndpoints()
public String getEndpoint()
public RedisOptions setEndpoints(List<String> endpoints)
endpoints
- list of socket addresses.@Deprecated public RedisOptions addEndpoint(String connectionString)
setConnectionString(String connectionString)
for a better namingconnectionString
- a string URI following the scheme: redis://[username:password@][host][:port][/database]@Deprecated public RedisOptions setEndpoint(String connectionString)
setConnectionString(String connectionString)
for a better namingconnectionString
- a string following the scheme: redis://[username:password@][host][:port][/[database]public RedisOptions addConnectionString(String connectionString)
connectionString
- a string URI following the scheme: redis://[username:password@][host][:port][/database]public RedisOptions setConnectionString(String connectionString)
connectionString
- a string following the scheme: redis://[username:password@][host][:port][/[database].public RedisTopology getTopology()
This is only meaningful in case of a replication Redis client. In case of a cluster and sentinel Redis client, topology is currently always discovered automatically and the topology mode is ignored.
public RedisOptions setTopology(RedisTopology topology)
This is only meaningful in case of a replication Redis client. In case of a cluster and sentinel Redis client, topology is currently always discovered automatically and the topology mode is ignored.
topology
- the topology modepublic int getMaxWaitingHandlers()
public RedisOptions setMaxWaitingHandlers(int maxWaitingHandlers)
maxWaitingHandlers
- max allowed queued waiting handlers.public String getMasterName()
This is only meaningful in case of a sentinel Redis client and is ignored otherwise.
public RedisOptions setMasterName(String masterName)
This is only meaningful in case of a sentinel Redis client and is ignored otherwise.
masterName
- the master set namepublic RedisRole getRole()
This is only meaningful in case of a sentinel Redis client and is ignored otherwise.
public RedisOptions setRole(RedisRole role)
This is only meaningful in case of a sentinel Redis client and is ignored otherwise.
role
- the rolepublic RedisReplicas getUseReplicas()
This is only meaningful in case of a replication and cluster Redis client and is ignored otherwise.
public RedisOptions setUseReplicas(RedisReplicas useReplicas)
This is only meaningful in case of a replication and cluster Redis client and is ignored otherwise.
useReplicas
- the cluster replica use mode.public int getMaxNestedArrays()
public RedisOptions setMaxNestedArrays(int maxNestedArrays)
maxNestedArrays
- the configured max nested arrays allowance.public TracingPolicy getTracingPolicy()
public RedisOptions setTracingPolicy(TracingPolicy tracingPolicy)
tracingPolicy
- the tracing policypublic PoolOptions getPoolOptions()
public int getPoolCleanerInterval()
A connection is marked invalid if it enters a exception or fatal state. It is marked unused if it is unused for longer than the recycle timeout.
The return value is in milliseconds. By default, the cleaning interval is 30 seconds. The value of -1 means connection pool cleaning is disabled.
public RedisOptions setPoolCleanerInterval(int poolCleanerInterval)
A connection is marked invalid if it enters a exception or fatal state. It is marked unused if it is unused for longer than the recycle timeout.
The value is in milliseconds. By default, the cleaning interval is 30 seconds. The value of -1 means connection pool cleaning is disabled.
poolCleanerInterval
- the cleaning interval in milliseconds, or -1 for neverpublic int getMaxPoolSize()
By default, the maximum pool size is 6.
public RedisOptions setMaxPoolSize(int maxPoolSize)
By default, the maximum pool size is 6.
When working with cluster or sentinel, this value should be at least the total number of cluster member (or number of sentinels + 1).
maxPoolSize
- the maximum pool sizepublic int getMaxPoolWaiting()
By default, the maximum number of waiting requests size is 24.
public RedisOptions setMaxPoolWaiting(int maxPoolWaiting)
By default, the maximum number of waiting requests size is 24.
maxPoolWaiting
- the maximum number of waiting requestspublic int getPoolRecycleTimeout()
The value is in milliseconds. By default, the recycle timeout is 3 minutes. The value of -1 means connection recycling is disabled.
public RedisOptions setPoolRecycleTimeout(int poolRecycleTimeout)
The value is in milliseconds. By default, the recycle timeout is 3 minutes. The value of -1 means connection recycling is disabled.
poolRecycleTimeout
- the recycle timeoutpublic String getPassword()
public RedisOptions setPassword(String password)
password
- the default passwordpublic boolean isProtocolNegotiation()
RESP
protocol negotiation during the connection handshake.
By default this is true
, but there are situations when using broken servers it may
be useful to skip this and always fallback to RESP2
without using the HELLO
command.public RedisOptions setProtocolNegotiation(boolean protocolNegotiation)
REST
protocol negotiation during the connection acquire.
By default this is true
, but there are situations when using broken servers it may
be useful to skip this and always fallback to RESP2
without using the HELLO
command.protocolNegotiation
- false to disable HELLO
(not recommended) unless reasons...public ProtocolVersion getPreferredProtocolVersion()
public RedisOptions setPreferredProtocolVersion(ProtocolVersion preferredProtocolVersion)
preferredProtocolVersion
- preferred protocol versionpublic String getPoolName()
public RedisOptions setPoolName(String poolName)
poolName
- the pool namepublic String getMetricsName()
public RedisOptions setMetricsName(String metricsName)
metricsName
- the metrics namepublic long getHashSlotCacheTTL()
This is only meaningful in case of a cluster Redis client and is ignored otherwise.
public RedisOptions setHashSlotCacheTTL(long hashSlotCacheTTL)
This is only meaningful in case of a cluster Redis client and is ignored otherwise.
hashSlotCacheTTL
- the TTL of the hash slot cache, in millispublic boolean isAutoFailover()
RedisRole.MASTER
and is ignored otherwise.
If enabled, the sentinel client will additionally create a connection to one sentinel node
and watch for failover events. When new master is elected, all connections to the old master
are automatically closed and new connections to the new master are created. Note that
these new connections will not have the same event handlers
(handler()
,
exceptionHandler()
and
endHandler()
), will not be
in the same streaming mode (pause()
,
resume()
and fetch()
),
and will not watch the same subscriptions (SUBSCRIBE
, PSUBSCRIBE
, etc.)
as the old ones. In other words, automatic failover makes sense for connections executing
regular commands, but not for connections used to subscribe to Redis pub/sub channels.
Note that there is a brief period of time between the old master failing and the new master being elected when the existing connections will temporarily fail all operations. After the new master is elected, the connections will automatically fail over and start working again.
public RedisOptions setAutoFailover(boolean autoFailover)
RedisRole.MASTER
and is ignored otherwise.
If enabled, the sentinel client will additionally create a connection to one sentinel node
and watch for failover events. When new master is elected, all connections to the old master
are automatically closed and new connections to the new master are created. Note that
these new connections will not have the same event handlers
(handler()
,
exceptionHandler()
and
endHandler()
), will not be
in the same streaming mode (pause()
,
resume()
and fetch()
),
and will not watch the same subscriptions (SUBSCRIBE
, PSUBSCRIBE
, etc.)
as the old ones. In other words, automatic failover makes sense for connections executing
regular commands, but not for connections used to subscribe to Redis pub/sub channels.
Note that there is a brief period of time between the old master failing and the new master being elected when the existing connections will temporarily fail all operations. After the new master is elected, the connections will automatically fail over and start working again.
autoFailover
- whether automatic failover should be enabledpublic JsonObject toJson()
Copyright © 2024 Eclipse. All rights reserved.