Class RedisOptions

java.lang.Object
io.vertx.redis.client.RedisOptions

public class RedisOptions extends Object
Redis Client Configuration options.
Author:
Paulo Lopes
  • Field Details

    • DEFAULT_ENDPOINT

      public static final String 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

      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 Details

    • 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
    • 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:
    • 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:
    • 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, 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

      public RedisOptions setPoolCleanerInterval(int poolCleanerInterval)
      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

      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
    • 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

      public RedisOptions setPoolMaxLifetime(long maxLifetime)
      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

      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 perform 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.
      Returns:
      true to perform negotiation.
    • setProtocolNegotiation

      public RedisOptions setProtocolNegotiation(boolean protocolNegotiation)
      Should the client perform RESP 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.
      Parameters:
      protocolNegotiation - false to disable HELLO (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

      @Deprecated public long getHashSlotCacheTTL()
      Deprecated.
    • getTopologyCacheTTL

      public long getTopologyCacheTTL()
      Returns the TTL of the topology cache. The TTL is expressed in milliseconds. Defaults to 1000 millis (1 second).

      This is only meaningful in case of a cluster or sentinel Redis client and is ignored otherwise.

      Returns:
      the TTL of the topology cache
    • setHashSlotCacheTTL

      @Deprecated public RedisOptions setHashSlotCacheTTL(long hashSlotCacheTTL)
      Deprecated.
    • setTopologyCacheTTL

      public RedisOptions setTopologyCacheTTL(long topologyCacheTTL)
      Sets the TTL of the topology cache. The TTL is expressed in milliseconds. Defaults to 1000 millis (1 second).

      This is only meaningful in case of a cluster or sentinel Redis client and is ignored otherwise.

      Parameters:
      topologyCacheTTL - the TTL of the topology 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 of 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.

      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 of 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.

      Parameters:
      autoFailover - whether automatic failover should be enabled
      Returns:
      fluent self
    • toJson

      public JsonObject toJson()
      Converts this object to JSON notation.
      Returns:
      JSON