Skip to content

Commit

Permalink
Add Redis 6 Support for Username (#104)
Browse files Browse the repository at this point in the history
Closes #104
  • Loading branch information
joschi committed Oct 21, 2021
1 parent 52433dc commit 5a0ba81
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ public RedisURI build() {
builder.withClientName(clientName);
}

if (password != null) {
if (username != null && password != null) {
builder.withAuthentication(username, password);
} else if (password != null) {
builder.withPassword(password);
}

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/io/dropwizard/redis/uri/RedisURIFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public abstract class RedisURIFactory implements Discoverable {
@JsonProperty
protected String clientName;

@JsonProperty
protected String username;

@JsonProperty
protected String password;

Expand All @@ -36,6 +39,14 @@ public void setClientName(final String clientName) {
this.clientName = clientName;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
import io.lettuce.core.RedisURI;
import org.hibernate.validator.constraints.NotEmpty;

import javax.validation.Valid;
import java.util.Collections;
import java.util.Set;

import javax.validation.Valid;

@JsonTypeName("sentinel")
public class SentinelModeURIFactory extends RedisURIFactory {
@Valid
Expand Down Expand Up @@ -48,7 +47,9 @@ public RedisURI build() {
builder.withClientName(clientName);
}

if (password != null) {
if (username != null && password != null) {
builder.withAuthentication(username, password);
} else if (password != null) {
builder.withPassword(password);
}

Expand Down

0 comments on commit 5a0ba81

Please sign in to comment.