public class RedisURI extends Object implements Serializable, ConnectionPoint
You have the following possibilities to create a RedisURI:
RedisURI.create("redis://localhost/");
create(String) for more options
RedisURI.Builder.redis("localhost", 6379).withPassword("password").withDatabase(1).build();
RedisURI.Builder.redis(String) and RedisURI.Builder.sentinel(String) for
more options.
new RedisURI("localhost", 6379, Duration.ofSeconds(60));
RedisURI uri = new RedisURI(); uri.setHost("localhost");
redisRedis Standalone (SSL)://[[username:]password@]host [:port][/database][?[timeout=timeout[d|h|m|s|ms|us|ns]] [ &database=database] [&clientName=clientName] [&libraryName=libraryName] [&libraryVersion=libraryVersion] [&verifyPeer=NONE|CA|FULL]]
redissRedis Standalone (Unix Domain Sockets)://[[username:]password@]host [:port][/database][?[timeout=timeout[d|h|m|s|ms|us|ns]] [ &database=database] [&clientName=clientName] [&libraryName=libraryName] [&libraryVersion=libraryVersion] [&verifyPeer=NONE|CA|FULL]]
redis-socketRedis Sentinel://[[username:]password@]path[?[timeout=timeout[d|h|m|s|ms|us|ns]][&database=database] [&clientName=clientName] [&libraryName=libraryName] [&libraryVersion=libraryVersion] [&verifyPeer=NONE|CA|FULL]]
redis-sentinel://[[username:]password@]host1 [:port1][, host2 [:port2]][, hostN [:portN]][/database][?[timeout=timeout[d|h|m|s|ms|us|ns]] [ &sentinelMasterId=sentinelMasterId] [&database=database] [&clientName=clientName] [&libraryName=libraryName] [&libraryVersion=libraryVersion] [&verifyPeer=NONE|CA|FULL]]
Timeout units
Hint: The database parameter within the query part has higher precedence than the database in the path.
RedisURI supports Redis Standalone, Redis Sentinel and Redis Cluster with plain, SSL, TLS and unix domain socket
connections.
RedisCredentials. Credentials are obtained at connection time from RedisCredentialsProvider. When configuring
username/password on the URI statically, then a StaticCredentialsProvider holds the configured information.
Notes
sentinel node.LettuceVersion.getVersion().| Modifier and Type | Class and Description |
|---|---|
static class |
RedisURI.Builder
Builder for Redis URI.
|
| Modifier and Type | Field and Description |
|---|---|
static Map<String,LongFunction<Duration>> |
CONVERTER_MAP |
static int |
DEFAULT_REDIS_PORT
The default redis port.
|
static int |
DEFAULT_SENTINEL_PORT
The default sentinel port.
|
static long |
DEFAULT_TIMEOUT
Default timeout: 60 sec
|
static Duration |
DEFAULT_TIMEOUT_DURATION |
static String |
PARAMETER_NAME_CLIENT_NAME |
static String |
PARAMETER_NAME_DATABASE |
static String |
PARAMETER_NAME_DATABASE_ALT |
static String |
PARAMETER_NAME_LIBRARY_NAME |
static String |
PARAMETER_NAME_LIBRARY_VERSION |
static String |
PARAMETER_NAME_SENTINEL_MASTER_ID |
static String |
PARAMETER_NAME_TIMEOUT |
static String |
PARAMETER_NAME_VERIFY_PEER |
static String |
URI_SCHEME_REDIS |
static String |
URI_SCHEME_REDIS_SECURE |
static String |
URI_SCHEME_REDIS_SECURE_ALT |
static String |
URI_SCHEME_REDIS_SENTINEL |
static String |
URI_SCHEME_REDIS_SENTINEL_SECURE |
static String |
URI_SCHEME_REDIS_SOCKET |
static String |
URI_SCHEME_REDIS_SOCKET_ALT |
static String |
URI_SCHEME_REDIS_TLS_ALT |
| Constructor and Description |
|---|
RedisURI()
Default empty constructor.
|
RedisURI(String host,
int port,
Duration timeout)
Constructor with host/port and timeout.
|
| Modifier and Type | Method and Description |
|---|---|
void |
applyAuthentication(RedisURI source)
Apply authentication from another
RedisURI. |
void |
applySsl(RedisURI source)
Apply authentication from another
RedisURI. |
static RedisURI.Builder |
builder()
Return a new
RedisURI.Builder to construct a RedisURI. |
static RedisURI.Builder |
builder(RedisURI source)
Create a new
RedisURI.Builder that is initialized from a plain RedisURI. |
static RedisURI |
create(String uri)
Create a Redis URI from an URI string.
|
static RedisURI |
create(String host,
int port)
Create a Redis URI from host and port.
|
static RedisURI |
create(URI uri)
Create a Redis URI from an URI string:
The uri must follow conventions of
URI |
boolean |
equals(Object o) |
String |
getClientName()
Returns the client name.
|
RedisCredentialsProvider |
getCredentialsProvider()
Returns the
RedisCredentialsProvider to use to authenticate Redis connections. |
int |
getDatabase()
Returns the Redis database number.
|
String |
getHost()
Returns the host.
|
String |
getLibraryName()
Returns the library name.
|
String |
getLibraryVersion()
Returns the library version.
|
int |
getPort()
Returns the Redis port.
|
String |
getSentinelMasterId()
Returns the Sentinel Master Id.
|
List<RedisURI> |
getSentinels() |
String |
getSocket()
Returns the Unix Domain Socket path.
|
Duration |
getTimeout()
Returns the command timeout for synchronous command execution.
|
SslVerifyMode |
getVerifyMode()
Returns the mode to verify peers when using
SSL. |
int |
hashCode() |
boolean |
isSsl()
Returns
true if SSL mode is enabled. |
boolean |
isStartTls()
Returns
true if StartTLS is enabled. |
boolean |
isVerifyPeer()
Returns whether to verify peers when using
SSL. |
void |
setAuthentication(char[] password)
Sets the password to use to authenticate Redis connections.
|
void |
setAuthentication(CharSequence password)
Sets the password to use to authenticate Redis connections.
|
void |
setAuthentication(String username,
char[] password)
Sets the username and password to use to authenticate Redis connections.
|
void |
setAuthentication(String username,
CharSequence password)
Sets the username and password to use to authenticate Redis connections.
|
void |
setClientName(String clientName)
Sets the client name to be applied on Redis connections.
|
void |
setCredentialsProvider(RedisCredentialsProvider credentialsProvider)
Sets the
RedisCredentialsProvider. |
void |
setDatabase(int database)
Sets the Redis database number.
|
void |
setHost(String host)
Sets the Redis host.
|
void |
setLibraryName(String libraryName)
Sets the library name to be applied on Redis connections.
|
void |
setLibraryVersion(String libraryVersion)
Sets the library version to be applied on Redis connections.
|
void |
setPort(int port)
Sets the Redis port.
|
void |
setSentinelMasterId(String sentinelMasterId)
Sets the Sentinel Master Id.
|
void |
setSocket(String socket)
Sets the Unix Domain Socket path.
|
void |
setSsl(boolean ssl)
Sets whether to use SSL.
|
void |
setStartTls(boolean startTls)
Returns whether StartTLS is enabled.
|
void |
setTimeout(Duration timeout)
Sets the command timeout for synchronous command execution.
|
void |
setVerifyPeer(boolean verifyPeer)
Sets whether to verify peers when using
SSL. |
void |
setVerifyPeer(SslVerifyMode verifyMode)
Sets how to verify peers when using
SSL. |
String |
toString() |
URI |
toURI()
Creates an URI based on the RedisURI if possible.
|
public static final String URI_SCHEME_REDIS_SENTINEL
public static final String URI_SCHEME_REDIS_SENTINEL_SECURE
public static final String URI_SCHEME_REDIS
public static final String URI_SCHEME_REDIS_SECURE
public static final String URI_SCHEME_REDIS_SECURE_ALT
public static final String URI_SCHEME_REDIS_TLS_ALT
public static final String URI_SCHEME_REDIS_SOCKET
public static final String URI_SCHEME_REDIS_SOCKET_ALT
public static final String PARAMETER_NAME_TIMEOUT
public static final String PARAMETER_NAME_DATABASE
public static final String PARAMETER_NAME_DATABASE_ALT
public static final String PARAMETER_NAME_SENTINEL_MASTER_ID
public static final String PARAMETER_NAME_CLIENT_NAME
public static final String PARAMETER_NAME_LIBRARY_NAME
public static final String PARAMETER_NAME_LIBRARY_VERSION
public static final String PARAMETER_NAME_VERIFY_PEER
public static final Map<String,LongFunction<Duration>> CONVERTER_MAP
public static final int DEFAULT_SENTINEL_PORT
public static final int DEFAULT_REDIS_PORT
public static final long DEFAULT_TIMEOUT
public static final Duration DEFAULT_TIMEOUT_DURATION
public static RedisURI.Builder builder()
RedisURI.Builder to construct a RedisURI.RedisURI.Builder to construct a RedisURI.public static RedisURI create(String host, int port)
host - the hostport - the portRedisURI containing details from the host and port.public static RedisURI create(String uri)
URIuri - The URI string.RedisURI containing details from the URI.public static RedisURI create(URI uri)
URIuri - The URI.RedisURI containing details from the URI.public static RedisURI.Builder builder(RedisURI source)
RedisURI.Builder that is initialized from a plain RedisURI.source - the initialization source, must not be null.public String getHost()
getHost in interface ConnectionPointpublic void setHost(String host)
host - the hostpublic String getSentinelMasterId()
public void setSentinelMasterId(String sentinelMasterId)
sentinelMasterId - the Sentinel Master Id.public int getPort()
getPort in interface ConnectionPointpublic void setPort(int port)
DEFAULT_REDIS_PORT.port - the Redis portpublic String getSocket()
getSocket in interface ConnectionPointpublic void setSocket(String socket)
socket - the Unix Domain Socket path.public void applyAuthentication(RedisURI source)
RedisURI. The authentication settings of the source URI will be applied
to this URI. That is in particular the RedisCredentialsProvider.source - must not be null.public void setAuthentication(CharSequence password)
This method effectively overwrites any existing RedisCredentialsProvider with a new one, containing an empty
username and the provided password.
password - the password to use to authenticate Redis connections.setCredentialsProvider(RedisCredentialsProvider)public void setAuthentication(char[] password)
This method effectively overwrites any existing RedisCredentialsProvider with a new one, containing an empty
username and the provided password.
password - the password to use to authenticate Redis connections.setCredentialsProvider(RedisCredentialsProvider)public void setAuthentication(String username, char[] password)
This method effectively overwrites any existing RedisCredentialsProvider with a new one, containing the provided
username and password.
username - the username to use to authenticate Redis connections.password - the password to use to authenticate Redis connections.setCredentialsProvider(RedisCredentialsProvider)public void setAuthentication(String username, CharSequence password)
This method effectively overwrites any existing RedisCredentialsProvider with a new one, containing the provided
username and password.
username - the username to use to authenticate Redis connections.password - the password to use to authenticate Redis connections.setCredentialsProvider(RedisCredentialsProvider)public RedisCredentialsProvider getCredentialsProvider()
RedisCredentialsProvider to use to authenticate Redis connections. Returns a static credentials
provider no explicit RedisCredentialsProvider was configured.RedisCredentialsProvider to use to authenticate Redis connectionspublic void setCredentialsProvider(RedisCredentialsProvider credentialsProvider)
RedisCredentialsProvider. Configuring a credentials provider resets the configured static
username/password.credentialsProvider - the credentials provider to use when authenticating a Redis connection.public Duration getTimeout()
public void setTimeout(Duration timeout)
timeout - the command timeout for synchronous command execution.public int getDatabase()
public void setDatabase(int database)
database - the Redis database number.public String getClientName()
public void setClientName(String clientName)
clientName - the client name.public String getLibraryName()
public void setLibraryName(String libraryName)
libraryName - the library name.public String getLibraryVersion()
public void setLibraryVersion(String libraryVersion)
libraryVersion - the library version.public void applySsl(RedisURI source)
RedisURI. The SSL settings of the source URI will be applied to this
URI. That is in particular SSL usage, peer verification and StartTLS.source - must not be null.public boolean isSsl()
true if SSL mode is enabled.true if SSL mode is enabled.public void setSsl(boolean ssl)
ssl - public boolean isVerifyPeer()
SSL.true to verify peers when using SSL.public SslVerifyMode getVerifyMode()
SSL.public void setVerifyPeer(boolean verifyPeer)
SSL. Sets peer verification also for already configured Redis
Sentinel nodes.verifyPeer - true to verify peers when using SSL.public void setVerifyPeer(SslVerifyMode verifyMode)
SSL. Sets peer verification also for already configured Redis
Sentinel nodes.verifyMode - verification mode to use when using SSL.public boolean isStartTls()
true if StartTLS is enabled.true if StartTLS is enabled.public void setStartTls(boolean startTls)
startTls - true if StartTLS is enabled.public List<RedisURI> getSentinels()
Redis Sentinel URIs.public URI toURI()
An URI an represent a Standalone address using host and port or socket addressing or a Redis Sentinel address using
host/port. A Redis Sentinel URI with multiple nodes using Unix Domain Sockets cannot be rendered to a URI.
IllegalStateException - if the URI cannot be rendered.public String toString()
Copyright © 2025 lettuce.io. All rights reserved.