Class RedisOptions
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe default Redis endpoint:redis://localhost:6379 -
Constructor Summary
ConstructorsConstructorDescriptionCreates a default configuration object using Redis server defaultsRedisOptions(JsonObject json) Copy from JSON constructor.RedisOptions(RedisOptions other) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionaddConnectionString(String connectionString) Adds a connection string (endpoint) to use while connecting to the Redis server.Get how Redis transactions are handled in cluster mode.Gets the Redis endpoint to useGets the list of Redis endpoints to use (mostly used while connecting to a cluster)longDeprecated.Get the name of the master set.intTune how much nested arrays are allowed on a Redis response.intGet the maximum size of the connection pool.intGet the maximum number of requests waiting for a connection from the pool.intThe client will always work on pipeline mode, this means that messages can start queueing.Get the net client options used to connect to the server.Get the default password for Redis connections.intGet how often the connection pool will be cleaned.longGet how long a connection can exist before it is recycled during connection pool cleaning.Get the connection pool name to be used for metrics reporting.intGet how long a connection can stay unused before it is recycled during connection pool cleaning.Returns the preferred protocol version to be used during protocol negotiation.getRole()Get the client role; that is, to which kind of node should the connection be established.Get how the topology should be obtained.longReturns the TTL of the topology cache.getType()Get the type of client to be created.getUser()Get the default username for Redis connections.Get whether to use replica nodes for read only queries.booleanReturns whether automatic failover is enabled.booleanShould the client performRESPprotocol negotiation during the connection handshake.setAutoFailover(boolean autoFailover) Returns whether automatic failover is enabled.setClusterTransactions(RedisClusterTransactions clusterTransactions) Set how Redis transactions are handled in cluster mode.setConnectionString(String connectionString) Sets a single connection string (endpoint) to use while connecting to the Redis server.setEndpoints(List<String> endpoints) Set the endpoints to use while connecting to the Redis server.setHashSlotCacheTTL(long hashSlotCacheTTL) Deprecated.setMasterName(String masterName) Set the name of the master set.setMaxNestedArrays(int maxNestedArrays) Tune how much nested arrays are allowed on a Redis response.setMaxPoolSize(int maxPoolSize) Set the maximum size of the connection pool.setMaxPoolWaiting(int maxPoolWaiting) Set the maximum number of requests waiting for a connection from the pool.setMaxWaitingHandlers(int maxWaitingHandlers) The client will always work on pipeline mode, this means that messages can start queueing.setMetricsName(String metricsName) Set the metrics name identifying the reported metrics, useful for grouping metrics with the same name.setNetClientOptions(NetClientOptions netClientOptions) Set the net client options to be used while connecting to the Redis server.setPassword(String password) Set the default password for Redis connections.setPoolCleanerInterval(int poolCleanerInterval) Set how often the connection pool will be cleaned.setPoolMaxLifetime(long maxLifetime) Set how long a connection can exist before it is recycled during connection pool cleaning.setPoolName(String poolName) Set the connection pool name to be used for metrics reporting.setPoolRecycleTimeout(int poolRecycleTimeout) Set how long a connection can stay unused before it is recycled during connection pool cleaning.setPreferredProtocolVersion(ProtocolVersion preferredProtocolVersion) Sets the preferred protocol version to be used during protocol negotiation.setProtocolNegotiation(boolean protocolNegotiation) Should the client performRESPprotocol negotiation during the connection acquire.Set the client role; that is, to which kind of node should the connection be established.setTopology(RedisTopology topology) Set how the topology should be obtained.setTopologyCacheTTL(long topologyCacheTTL) Sets the TTL of the topology cache.setTracingPolicy(TracingPolicy tracingPolicy) Set the tracing policy for the client behavior when Vert.x has tracing enabled.setType(RedisClientType type) Set the desired client type to be created.Set the default username for Redis connections.setUseReplicas(RedisReplicas useReplicas) Set whether to use replica nodes for read only queries.toJson()Converts this object to JSON notation.
-
Field Details
-
DEFAULT_ENDPOINT
The default Redis endpoint:redis://localhost:6379- See Also:
-
-
Constructor Details
-
RedisOptions
public RedisOptions()Creates a default configuration object using Redis server defaults -
RedisOptions
-
RedisOptions
-
-
Method Details
-
getType
Get the type of client to be created.- Returns:
- the desired client type.
-
setType
Set the desired client type to be created.- Parameters:
type- the client type.- Returns:
- fluent self.
-
getNetClientOptions
Get the net client options used to connect to the server.- Returns:
- the net socket options.
-
setNetClientOptions
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
-
addConnectionString
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:
-
setConnectionString
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:
-
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
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
-
setEndpoints
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
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
-
setMasterName
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
-
setRole
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
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
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
Get how Redis transactions are handled in cluster mode.- Returns:
- how transactions are handled
-
setClusterTransactions
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
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
- Returns:
- the tracing policy
-
setTracingPolicy
Set the tracing policy for the client behavior when Vert.x has tracing enabled.- Parameters:
tracingPolicy- the tracing policy- Returns:
- fluent self.
-
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, too old 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. It is marked too old if it exists longer than the maximum lifetime.
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
Set how often the connection pool will be cleaned. Cleaning the connection pool means scanning for unused, too old 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. It is marked too old if it exists longer than the maximum lifetime.
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
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
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
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
-
getPoolMaxLifetime
public long getPoolMaxLifetime()Get how long a connection can exist before it is recycled during connection pool cleaning.The value is in milliseconds. By default, the maximum lifetime is -1. The value of -1 means connections are never too old.
As opposed to recycle timeout, this property does not take into account when the connection was last used. If the connection is too old, it is evicted even if it was used very recently.
- Returns:
- the maximum lifetime
-
setPoolMaxLifetime
Set how long a connection can exist before it is recycled during connection pool cleaning.The value is in milliseconds. By default, the maximum lifetime is -1. The value of -1 means connections are never too old.
As opposed to recycle timeout, this property does not take into account when the connection was last used. If the connection is too old, it is evicted even if it was used very recently.
- Parameters:
maxLifetime- the maximum lifetime- Returns:
- fluent self
-
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
Set the default username for Redis connections.- Parameters:
user- the default username- Returns:
- fluent self
-
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
Set the default password for Redis connections.- Parameters:
password- the default password- Returns:
- fluent self
-
isProtocolNegotiation
public boolean isProtocolNegotiation()Should the client performRESPprotocol 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 toRESP2without using theHELLOcommand.- Returns:
- true to perform negotiation.
-
setProtocolNegotiation
Should the client performRESPprotocol 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 toRESP2without using theHELLOcommand.- Parameters:
protocolNegotiation- false to disableHELLO(not recommended) unless reasons...- Returns:
- fluent self
-
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
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
Get the connection pool name to be used for metrics reporting. The default name is a random UUID.- Returns:
- the pool name
-
setPoolName
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
- Returns:
- the metrics name identifying the reported metrics.
-
setMetricsName
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
Deprecated. -
getTopologyCacheTTL
-
setHashSlotCacheTTL
Deprecated. -
setTopologyCacheTTL
-
isAutoFailover
public boolean isAutoFailover()Returns whether automatic failover is enabled. This only makes sense for sentinel clients with role ofRedisRole.MASTERand 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
Returns whether automatic failover is enabled. This only makes sense for sentinel clients with role ofRedisRole.MASTERand 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
-