Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
Adding Redis db index to not have default db index of 0 always and us…
Browse files Browse the repository at this point in the history
…ername for ACL. (#3847)

Co-authored-by: Anup Chatterjee <[email protected]>
  • Loading branch information
Anupchat and anupVMware authored Nov 25, 2023
1 parent 07fd73a commit fc3657a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ public RedisProperties(ConductorProperties conductorProperties) {

private int numTestsPerEvictionRun = 3;

private int database = 0;

private String username = null;

public int getNumTestsPerEvictionRun() {
return numTestsPerEvictionRun;
}
Expand Down Expand Up @@ -283,4 +287,20 @@ public RetryPolicyFactory getConnectionRetryPolicy() {
return () -> new RetryNTimes(maxRetryAttempts, false);
}
}

public int getDatabase() {
return database;
}

public void setDatabase(int database) {
this.database = database;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,33 @@ protected JedisCommands createJedisCommands(
}
// We use the password of the first sentinel host as password and sentinelPassword
String password = getPassword(hostSupplier.getHosts());
if (password != null) {
if (properties.getUsername() != null && password != null) {
return new JedisSentinel(
new JedisSentinelPool(
properties.getClusterName(),
sentinels,
genericObjectPoolConfig,
Protocol.DEFAULT_TIMEOUT,
Protocol.DEFAULT_TIMEOUT,
properties.getUsername(),
password,
Protocol.DEFAULT_DATABASE,
properties.getDatabase(),
null,
Protocol.DEFAULT_TIMEOUT,
Protocol.DEFAULT_TIMEOUT,
properties.getUsername(),
password,
null));
} else if (password != null) {
return new JedisSentinel(
new JedisSentinelPool(
properties.getClusterName(),
sentinels,
genericObjectPoolConfig,
Protocol.DEFAULT_TIMEOUT,
Protocol.DEFAULT_TIMEOUT,
password,
properties.getDatabase(),
null,
Protocol.DEFAULT_TIMEOUT,
Protocol.DEFAULT_TIMEOUT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,29 @@ protected JedisCommands createJedisCommands(
config.setMaxTotal(properties.getMaxConnectionsPerHost());
log.info("Starting conductor server using redis_standalone.");
Host host = hostSupplier.getHosts().get(0);
return new JedisStandalone(getJedisPool(config, host));
return new JedisStandalone(getJedisPool(config, host, properties));
}

private JedisPool getJedisPool(JedisPoolConfig config, Host host) {
if (host.getPassword() != null) {
private JedisPool getJedisPool(JedisPoolConfig config, Host host, RedisProperties properties) {
if (properties.getUsername() != null && host.getPassword() != null) {
log.info("Connecting to Redis Standalone with AUTH");
return new JedisPool(
config,
host.getHostName(),
host.getPort(),
Protocol.DEFAULT_TIMEOUT,
host.getPassword());
properties.getUsername(),
host.getPassword(),
properties.getDatabase());
} else if (host.getPassword() != null) {
log.info("Connecting to Redis Standalone with AUTH");
return new JedisPool(
config,
host.getHostName(),
host.getPort(),
Protocol.DEFAULT_TIMEOUT,
host.getPassword(),
properties.getDatabase());
} else {
return new JedisPool(config, host.getHostName(), host.getPort());
}
Expand Down

0 comments on commit fc3657a

Please sign in to comment.