public class RedisURI extends Object implements Serializable, ConnectionPoint
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, 60, TimeUnit.SECONDS);
RedisURI uri = new RedisURI(); uri.setHost("localhost");
redisRedis Standalone (SSL)://
[[email protected]]host [:
port][/
database][?
[timeout=timeout[d|h|m|s|ms|us|ns]] [ &database=database] [&clientName=clientName]]
redissRedis Standalone (Unix Domain Sockets)://
[[email protected]]host [:
port][/
database][?
[timeout=timeout[d|h|m|s|ms|us|ns]] [ &database=database] [&clientName=clientName]]
redis-socketRedis Sentinel://
[[email protected]]path[?
[timeout=timeout[d|h|m|s|ms|us|ns]][&database=database] [&clientName=clientName]]
redis-sentinel://
[[email protected]]host1 [:
port1][, host2 [:
port2]][, hostN [:
portN]][/
database][?
[timeout=timeout[d|h|m|s|ms|us|ns]] [ &sentinelMasterId=sentinelMasterId] [&database=database] [&clientName=clientName]]
Note: When using Redis Sentinel, the password from the URI applies to the data nodes only. Sentinel authentication must be
configured for each sentinel node
.
Schemes
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.Modifier and Type | Class and Description |
---|---|
static class |
RedisURI.Builder
Builder for Redis URI.
|
Modifier and Type | Field and Description |
---|---|
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 TimeUnit |
DEFAULT_TIMEOUT_UNIT |
static String |
PARAMETER_NAME_CLIENT_NAME |
static String |
PARAMETER_NAME_DATABASE |
static String |
PARAMETER_NAME_DATABASE_ALT |
static String |
PARAMETER_NAME_SENTINEL_MASTER_ID |
static String |
PARAMETER_NAME_TIMEOUT |
static Map<String,TimeUnit> |
TIME_UNIT_MAP |
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.
|
RedisURI(String host,
int port,
long timeout,
TimeUnit unit)
Deprecated.
since 5.0, use
RedisURI(String, int, Duration) |
Modifier and Type | Method and Description |
---|---|
static RedisURI.Builder |
builder()
Returns a new
RedisURI.Builder to construct a 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.
|
int |
getDatabase()
Returns the Redis database number.
|
String |
getHost()
Returns the host.
|
char[] |
getPassword()
Returns the password.
|
int |
getPort()
Returns the Redis port.
|
SocketAddress |
getResolvedAddress()
Deprecated.
since 5.2. Will be removed with 6.0. Use
SocketAddressResolver.resolve(RedisURI) . |
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.
|
int |
hashCode() |
boolean |
isSsl()
Returns
true if SSL mode is enabled. |
boolean |
isStartTls()
Returns
true if StartTLS is enabled. |
boolean |
isVerifyPeer()
Sets whether to verify peers when using
SSL . |
void |
setClientName(String clientName)
Sets the client name to be applied on Redis connections.
|
void |
setDatabase(int database)
Sets the Redis database number.
|
void |
setHost(String host)
Sets the Redis host.
|
void |
setPassword(char[] password)
Sets the password.
|
void |
setPassword(CharSequence password)
Sets the password.
|
void |
setPassword(String password)
Sets the password.
|
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 . |
String |
toString() |
URI |
toURI()
Creates an URI based on the RedisURI.
|
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 int DEFAULT_SENTINEL_PORT
public static final int DEFAULT_REDIS_PORT
public static final long DEFAULT_TIMEOUT
public static final TimeUnit DEFAULT_TIMEOUT_UNIT
public static final Duration DEFAULT_TIMEOUT_DURATION
public RedisURI()
public RedisURI(String host, int port, Duration timeout)
host
- the hostport
- the porttimeout
- timeout valuetimeout
- unit of the timeout value@Deprecated public RedisURI(String host, int port, long timeout, TimeUnit unit)
RedisURI(String, int, Duration)
host
- the hostport
- the porttimeout
- timeout valueunit
- unit of the timeout valuepublic 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 host.port
- the port.RedisURI
containing details from the host
and port
.public static RedisURI create(String uri)
URI
uri
- The URI string.RedisURI
containing details from the URI.public static RedisURI create(URI uri)
URI
uri
- The URI.RedisURI
containing details from the URI.public String getHost()
getHost
in interface ConnectionPoint
public void setHost(String host)
host
- the host.public String getSentinelMasterId()
public void setSentinelMasterId(String sentinelMasterId)
sentinelMasterId
- the Sentinel Master Id.public int getPort()
getPort
in interface ConnectionPoint
public void setPort(int port)
DEFAULT_REDIS_PORT
.port
- the Redis port.public String getSocket()
getSocket
in interface ConnectionPoint
public void setSocket(String socket)
socket
- the Unix Domain Socket path.public char[] getPassword()
public void setPassword(String password)
password
- the password, must not be null
.public void setPassword(CharSequence password)
password
- the password, must not be null
.public void setPassword(char[] password)
password
- the password, must not be null
.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 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 void setVerifyPeer(boolean verifyPeer)
SSL
. Sets peer verification also for already configured Redis
Sentinel nodes.verifyPeer
- true
to verify peers 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()
@Deprecated public SocketAddress getResolvedAddress()
SocketAddressResolver.resolve(RedisURI)
.SocketAddress
based either on host/port or the socket.Copyright © 2020 lettuce.io. All rights reserved.