Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new constructor to support Redis username #18

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/main/java/org/casbin/adapter/RedisAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@
private String key;
private Jedis jedis;

public RedisAdapter(String host, int port) { newRedisAdapter(host, port, "casbin_rules", null); }
public RedisAdapter(String host, int port) { newRedisAdapter(host, port, "casbin_rules", null, null); }

public RedisAdapter(String host, int port, String password) {
newRedisAdapter(host, port, "casbin_rules", password);
newRedisAdapter(host, port, "casbin_rules", null, password);

Check warning on line 43 in src/main/java/org/casbin/adapter/RedisAdapter.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/casbin/adapter/RedisAdapter.java#L43

Added line #L43 was not covered by tests
}

public RedisAdapter(String host, int port, String key, String password) {
newRedisAdapter(host, port, key, password);
newRedisAdapter(host, port, key, null, password);
}

Check warning on line 48 in src/main/java/org/casbin/adapter/RedisAdapter.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/casbin/adapter/RedisAdapter.java#L47-L48

Added lines #L47 - L48 were not covered by tests

public RedisAdapter(String host, int port, String key, String username, String password) {
newRedisAdapter(host, port, key, username, password);

Check warning on line 51 in src/main/java/org/casbin/adapter/RedisAdapter.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/casbin/adapter/RedisAdapter.java#L50-L51

Added lines #L50 - L51 were not covered by tests
}

/**
Expand Down Expand Up @@ -159,12 +163,17 @@
}
}

private void newRedisAdapter(String host, int port, String key, String password) {
private void newRedisAdapter(String host, int port, String key, String username, String password) {
this.key = key;

jedis = new Jedis(host, port);
if (password != null) {
jedis.auth(password);
if (username != null) {
jedis.auth(username, password);

Check warning on line 172 in src/main/java/org/casbin/adapter/RedisAdapter.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/casbin/adapter/RedisAdapter.java#L172

Added line #L172 was not covered by tests
}
else {
jedis.auth(password);

Check warning on line 175 in src/main/java/org/casbin/adapter/RedisAdapter.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/casbin/adapter/RedisAdapter.java#L175

Added line #L175 was not covered by tests
}
}

Util.logPrintf("Redis service is running ", jedis.ping());
Expand Down
Loading