Class RedisConf
Redis 6 introduced ACL users, so a connection is identified by a username as well as a
password. A configuration that supplies only a password authenticates as default, which is
the pre-ACL behaviour and remains supported.
Instances are value objects and are used as cache keys by
RedisConnector, so two configurations describing the same
connection share one client.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intRedis' own default port, used whenever a port is not given. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a config with the given address, port, and password, authenticating asdefault.Creates a config with the given address, port, username, and password.RedisConf(@NotNull String address, int port, @Nullable String username, @Nullable String password, int database, boolean ssl) Creates a config with every connection setting stated. -
Method Summary
Modifier and TypeMethodDescriptionbooleanstatic @NotNull RedisConfParses a Redis connection URL.@NotNull io.lettuce.core.RedisURIgetURI()inthashCode()static @NotNull RedisConfCreates a RedisConfig object with the given address Defaults: port 6379, no authenticationstatic @NotNull RedisConfCreates a RedisConfig object with the given address and port Defaults: no authenticationstatic @NotNull RedisConfCreates a RedisConfig object with the given address, port, and password Defaults: authenticates asdefaultstatic @NotNull RedisConfCreates a RedisConfig object with the given address, port, username, and passwordtoString()Never includes the password.
-
Field Details
-
DEFAULT_PORT
public static final int DEFAULT_PORTRedis' own default port, used whenever a port is not given.- See Also:
-
-
Constructor Details
-
RedisConf
-
RedisConf
public RedisConf(@NotNull @NotNull String address, int port, @Nullable @Nullable String username, @Nullable @Nullable String password) Creates a config with the given address, port, username, and password.- Parameters:
username- Nullable (to authenticate asdefault)password- Nullable (for no authentication)
-
RedisConf
public RedisConf(@NotNull @NotNull String address, int port, @Nullable @Nullable String username, @Nullable @Nullable String password, int database, boolean ssl) Creates a config with every connection setting stated.- Parameters:
username- Nullable (to authenticate asdefault)password- Nullable (for no authentication)database- Logical database indexssl- Whether to connect over TLS
-
-
Method Details
-
getURI
@NotNull public @NotNull io.lettuce.core.RedisURI getURI() -
of
-
of
-
of
-
of
-
fromUrl
Parses a Redis connection URL.Accepted forms, where everything after the host is optional:
redis://host redis://host:6380 redis://:password@host redis://username:password@host:6380/3 rediss://username:password@host (TLS)
Credentials must be written with a colon.
redis://value@hostis rejected rather than guessed at. Lettuce reads a colon-less userInfo as the password, soredis://myuser@hostagainst a server withrequirepassset would connect successfully asdefaultwhile the caller believed they were authenticating asmyuser. That failure is silent and is the one this whole ACL arrangement exists to prevent, so the ambiguous form is an error. Writeredis://myuser:secret@hostfor an ACL user, orredis://:secret@hostfor a password alone.- Parameters:
url- the connection URL- Returns:
- the parsed configuration
- Throws:
IllegalArgumentException- if the URL is not a Redis URL this can represent. The message never contains the URL itself, because it would carry the password into the log.
-
equals
-
hashCode
-
toString
-