Class RedisOptions
- java.lang.Object
-
- io.vertx.redis.client.RedisOptions
-
public class RedisOptions extends Object
Redis Client Configuration options.- Author:
- Paulo Lopes
-
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_ENDPOINT
The default Redis endpoint:redis://localhost:6379
-
Constructor Summary
Constructors Constructor Description RedisOptions()
Creates a default configuration object using Redis server defaultsRedisOptions(JsonObject json)
Copy from JSON constructor.RedisOptions(RedisOptions other)
Copy constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description RedisOptions
addConnectionString(String connectionString)
Adds a connection string (endpoint) to use while connecting to the Redis server.RedisOptions
addEndpoint(String connectionString)
Deprecated.seesetConnectionString(String connectionString)
for a better namingRedisClusterTransactions
getClusterTransactions()
Get how Redis transactions are handled in cluster mode.String
getEndpoint()
Gets the Redis endpoint to useList<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 Redis connections.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.String
getUser()
Get the default username for Redis connections.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 performRESP
protocol negotiation during the connection handshake.RedisOptions
setAutoFailover(boolean autoFailover)
Returns whether automatic failover is enabled.RedisOptions
setClusterTransactions(RedisClusterTransactions clusterTransactions)
Set how Redis transactions are handled in cluster mode.RedisOptions
setConnectionString(String connectionString)
Sets a single connection string (endpoint) to use while connecting to the Redis server.RedisOptions
setEndpoint(String connectionString)
Deprecated.seesetConnectionString(String connectionString)
for a better namingRedisOptions
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 Redis 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 performRESP
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
setUser(String user)
Set the default username for Redis connections.RedisOptions
setUseReplicas(RedisReplicas useReplicas)
Set whether to use replica nodes for read only queries.JsonObject
toJson()
Converts this object to JSON notation.
-
-
-
Field Detail
-
DEFAULT_ENDPOINT
public static final String DEFAULT_ENDPOINT
The default Redis endpoint:redis://localhost:6379
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
RedisOptions
public RedisOptions()
Creates a default configuration object using Redis server defaults
-
RedisOptions
public RedisOptions(RedisOptions other)
Copy constructor.- Parameters:
other
- the object to clone.
-
RedisOptions
public RedisOptions(JsonObject json)
Copy from JSON constructor.- Parameters:
json
- source json
-
-
Method Detail
-
getType
public RedisClientType getType()
Get the type of client to be created.- Returns:
- the desired client type.
-
setType
public RedisOptions setType(RedisClientType type)
Set the desired client type to be created.- Parameters:
type
- the client type.- Returns:
- fluent self.
-
getNetClientOptions
public NetClientOptions getNetClientOptions()
Get the net client options used to connect to the server.- Returns:
- the net socket options.
-
setNetClientOptions
public RedisOptions setNetClientOptions(NetClientOptions netClientOptions)
Set the net client options to be used while connecting to the Redis server. Use this to tune your connection.- Parameters:
netClientOptions
- custom net client options.- Returns:
- fluent self.
-
getEndpoint
public String getEndpoint()
Gets the Redis endpoint to use- Returns:
- the Redis connection string URI
-
addEndpoint
@Deprecated public RedisOptions addEndpoint(String connectionString)
Deprecated.seesetConnectionString(String connectionString)
for a better namingAdds an endpoint to use while connecting to the Redis server. Only the cluster mode will consider more than 1 element. If more are provided, they are not considered by the client when in single server mode.- Parameters:
connectionString
- a string URI following the scheme: redis://[username:password@][host][:port][/database]- Returns:
- fluent self.
-
setEndpoint
@Deprecated public RedisOptions setEndpoint(String connectionString)
Deprecated.seesetConnectionString(String connectionString)
for a better namingSets a single connection string to use while connecting to the Redis server. Will replace the previously configured connection strings.- Parameters:
connectionString
- a string following the scheme: redis://[username:password@][host][:port][/[database]- Returns:
- fluent self.
-
addConnectionString
public RedisOptions addConnectionString(String connectionString)
Adds a connection string (endpoint) to use while connecting to the Redis server. Only the cluster mode will consider more than 1 element. If more are provided, they are not considered by the client when in single server mode.- Parameters:
connectionString
- a string URI following the scheme: redis://[username:password@][host][:port][/database]- Returns:
- fluent self.
- See Also:
- Redis scheme on iana.org
-
setConnectionString
public RedisOptions setConnectionString(String connectionString)
Sets a single connection string (endpoint) to use while connecting to the Redis server. Will replace the previously configured connection strings.- Parameters:
connectionString
- a string following the scheme: redis://[username:password@][host][:port][/[database].- Returns:
- fluent self.
- See Also:
- Redis scheme on iana.org
-
getTopology
public RedisTopology getTopology()
Get how the topology should be obtained. By default, the topology is discovered automatically.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.
- Returns:
- the topology mode
-
setTopology
public RedisOptions setTopology(RedisTopology topology)
Set how the topology should be obtained. By default, the topology is discovered automatically.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.
- Parameters:
topology
- the topology mode- Returns:
- fluent self
-
getEndpoints
public List<String> getEndpoints()
Gets the list of Redis endpoints to use (mostly used while connecting to a cluster)- Returns:
- list of socket addresses.
-
setEndpoints
public RedisOptions setEndpoints(List<String> endpoints)
Set the endpoints to use while connecting to the Redis server. Only the cluster mode will consider more than 1 element. If more are provided, they are not considered by the client when in single server mode.- Parameters:
endpoints
- list of socket addresses.- Returns:
- fluent self.
-
getMaxWaitingHandlers
public int getMaxWaitingHandlers()
The client will always work on pipeline mode, this means that messages can start queueing. You can control how much backlog you're willing to accept. This methods returns how much handlers is the client willing to queue.- Returns:
- max allowed queued waiting handlers.
-
setMaxWaitingHandlers
public RedisOptions setMaxWaitingHandlers(int maxWaitingHandlers)
The client will always work on pipeline mode, this means that messages can start queueing. You can control how much backlog you're willing to accept. This methods sets how much handlers is the client willing to queue.- Parameters:
maxWaitingHandlers
- max allowed queued waiting handlers.- Returns:
- fluent self.
-
getMasterName
public String getMasterName()
Get the name of the master set.This is only meaningful in case of a sentinel Redis client and is ignored otherwise.
- Returns:
- the master set name
-
setMasterName
public RedisOptions setMasterName(String masterName)
Set the name of the master set.This is only meaningful in case of a sentinel Redis client and is ignored otherwise.
- Parameters:
masterName
- the master set name- Returns:
- fluent self
-
getRole
public RedisRole getRole()
Get the client role; that is, to which kind of node should the connection be established.This is only meaningful in case of a sentinel Redis client and is ignored otherwise.
- Returns:
- the role
-
setRole
public RedisOptions setRole(RedisRole role)
Set the client role; that is, to which kind of node should the connection be established.This is only meaningful in case of a sentinel Redis client and is ignored otherwise.
- Parameters:
role
- the role- Returns:
- fluent self
-
getUseReplicas
public RedisReplicas getUseReplicas()
Get whether to use replica nodes for read only queries.This is only meaningful in case of a replication and cluster Redis client and is ignored otherwise.
- Returns:
- the cluster replica node use mode.
-
setUseReplicas
public RedisOptions setUseReplicas(RedisReplicas useReplicas)
Set whether to use replica nodes for read only queries.This is only meaningful in case of a replication and cluster Redis client and is ignored otherwise.
- Parameters:
useReplicas
- the cluster replica use mode.- Returns:
- fluent self.
-
getClusterTransactions
public RedisClusterTransactions getClusterTransactions()
Get how Redis transactions are handled in cluster mode.- Returns:
- how transactions are handled
-
setClusterTransactions
public RedisOptions setClusterTransactions(RedisClusterTransactions clusterTransactions)
Set how Redis transactions are handled in cluster mode.- Parameters:
clusterTransactions
- transaction handling mode- Returns:
- fluent self
-
getMaxNestedArrays
public int getMaxNestedArrays()
Tune how much nested arrays are allowed on a Redis response. This affects the parser performance.- Returns:
- the configured max nested arrays allowance.
-
setMaxNestedArrays
public RedisOptions setMaxNestedArrays(int maxNestedArrays)
Tune how much nested arrays are allowed on a Redis response. This affects the parser performance.- Parameters:
maxNestedArrays
- the configured max nested arrays allowance.- Returns:
- fluent self.
-
getTracingPolicy
public TracingPolicy getTracingPolicy()
- Returns:
- the tracing policy
-
setTracingPolicy
public RedisOptions setTracingPolicy(TracingPolicy tracingPolicy)
Set the tracing policy for the client behavior when Vert.x has tracing enabled.- Parameters:
tracingPolicy
- the tracing policy- Returns:
- fluent self.
-
getPoolOptions
public PoolOptions getPoolOptions()
- Returns:
- the pool options
-
getPoolCleanerInterval
public int getPoolCleanerInterval()
Get how often the connection pool will be cleaned. Cleaning the connection pool means scanning for unused and invalid connections and if any are found, they are forcibly closed and evicted from the pool.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.
- Returns:
- the cleaning interval in milliseconds, or -1 for never
-
setPoolCleanerInterval
public RedisOptions setPoolCleanerInterval(int poolCleanerInterval)
Set how often the connection pool will be cleaned. Cleaning the connection pool means scanning for unused and invalid connections and if any are found, they are forcibly closed and evicted from the pool.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.
- Parameters:
poolCleanerInterval
- the cleaning interval in milliseconds, or -1 for never- Returns:
- fluent self
-
getMaxPoolSize
public int getMaxPoolSize()
Get the maximum size of the connection pool.By default, the maximum pool size is 6.
- Returns:
- the maximum pool size
-
setMaxPoolSize
public RedisOptions setMaxPoolSize(int maxPoolSize)
Set the maximum size of the connection pool.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).
- Parameters:
maxPoolSize
- the maximum pool size- Returns:
- fluent self
-
getMaxPoolWaiting
public int getMaxPoolWaiting()
Get the maximum number of requests waiting for a connection from the pool.By default, the maximum number of waiting requests size is 24.
- Returns:
- the maximum number of waiting requests
-
setMaxPoolWaiting
public RedisOptions setMaxPoolWaiting(int maxPoolWaiting)
Set the maximum number of requests waiting for a connection from the pool.By default, the maximum number of waiting requests size is 24.
- Parameters:
maxPoolWaiting
- the maximum number of waiting requests- Returns:
- fluent self
-
getPoolRecycleTimeout
public int getPoolRecycleTimeout()
Get how long a connection can stay unused before it is recycled during connection pool cleaning.The value is in milliseconds. By default, the recycle timeout is 3 minutes. The value of -1 means connection recycling is disabled.
- Returns:
- the recycle timeout
-
setPoolRecycleTimeout
public RedisOptions setPoolRecycleTimeout(int poolRecycleTimeout)
Set how long a connection can stay unused before it is recycled during connection pool cleaning.The value is in milliseconds. By default, the recycle timeout is 3 minutes. The value of -1 means connection recycling is disabled.
- Parameters:
poolRecycleTimeout
- the recycle timeout- Returns:
- fluent self
-
getUser
public String getUser()
Get the default username for Redis connections. If not set, it will try to extract it from the current default endpoint (getEndpoint()
).- Returns:
- username
-
setUser
public RedisOptions setUser(String user)
Set the default username for Redis connections.- Parameters:
user
- the default username- Returns:
- fluent self
-
getPassword
public String getPassword()
Get the default password for Redis connections. If not set, it will try to extract it from the current default endpoint (getEndpoint()
).- Returns:
- password
-
setPassword
public RedisOptions setPassword(String password)
Set the default password for Redis connections.- Parameters:
password
- the default password- Returns:
- fluent self
-
isProtocolNegotiation
public boolean isProtocolNegotiation()
Should the client performRESP
protocol negotiation during the connection handshake. By default, this istrue
, but there are situations when using broken servers it may be useful to skip this and always fallback toRESP2
without using theHELLO
command.- Returns:
- true to perform negotiation.
-
setProtocolNegotiation
public RedisOptions setProtocolNegotiation(boolean protocolNegotiation)
Should the client performRESP
protocol negotiation during the connection acquire. By default, this istrue
, but there are situations when using broken servers it may be useful to skip this and always fallback toRESP2
without using theHELLO
command.- Parameters:
protocolNegotiation
- false to disableHELLO
(not recommended) unless reasons...- Returns:
- fluent self
-
getPreferredProtocolVersion
public ProtocolVersion getPreferredProtocolVersion()
Returns the preferred protocol version to be used during protocol negotiation. When not set, defaults to RESP 3. When protocol negotiation is disabled, this setting has no effect.- Returns:
- preferred protocol version
-
setPreferredProtocolVersion
public RedisOptions setPreferredProtocolVersion(ProtocolVersion preferredProtocolVersion)
Sets the preferred protocol version to be used during protocol negotiation. When not set, defaults to RESP 3. When protocol negotiation is disabled, this setting has no effect.- Parameters:
preferredProtocolVersion
- preferred protocol version- Returns:
- fluent self
-
getPoolName
public String getPoolName()
Get the connection pool name to be used for metrics reporting. The default name is a random UUID.- Returns:
- the pool name
-
setPoolName
public RedisOptions setPoolName(String poolName)
Set the connection pool name to be used for metrics reporting. The default name is a random UUID.- Parameters:
poolName
- the pool name- Returns:
- fluent self
-
getMetricsName
public String getMetricsName()
- Returns:
- the metrics name identifying the reported metrics.
-
setMetricsName
public RedisOptions setMetricsName(String metricsName)
Set the metrics name identifying the reported metrics, useful for grouping metrics with the same name.- Parameters:
metricsName
- the metrics name- Returns:
- a reference to this, so the API can be used fluently
-
getHashSlotCacheTTL
public long getHashSlotCacheTTL()
Returns the TTL of the hash slot cache. The TTL is expressed in milliseconds. Defaults to 1000 millis (1 second).This is only meaningful in case of a cluster Redis client and is ignored otherwise.
- Returns:
- the TTL of the hash slot cache
-
setHashSlotCacheTTL
public RedisOptions setHashSlotCacheTTL(long hashSlotCacheTTL)
Sets the TTL of the hash slot cache. The TTL is expressed in milliseconds. Defaults to 1000 millis (1 second).This is only meaningful in case of a cluster Redis client and is ignored otherwise.
- Parameters:
hashSlotCacheTTL
- the TTL of the hash slot cache, in millis- Returns:
- fluent self
-
isAutoFailover
public boolean isAutoFailover()
Returns whether automatic failover is enabled. This only makes sense for sentinel clients with role ofRedisRole.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()
andendHandler()
), will not be in the same streaming mode (pause()
,resume()
andfetch()
), 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.
- Returns:
- whether automatic failover is enabled
-
setAutoFailover
public RedisOptions setAutoFailover(boolean autoFailover)
Returns whether automatic failover is enabled. This only makes sense for sentinel clients with role ofRedisRole.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()
andendHandler()
), will not be in the same streaming mode (pause()
,resume()
andfetch()
), 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.
- Parameters:
autoFailover
- whether automatic failover should be enabled- Returns:
- fluent self
-
toJson
public JsonObject toJson()
Converts this object to JSON notation.- Returns:
- JSON
-
-