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

Commit 0090045

Browse files
committed
Adding Redis db index to not have default db index of 0 always and username for ACL.
1 parent 9669d46 commit 0090045

File tree

3 files changed

+54
-6
lines changed

3 files changed

+54
-6
lines changed

redis-persistence/src/main/java/com/netflix/conductor/redis/config/RedisProperties.java

+20
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ public RedisProperties(ConductorProperties conductorProperties) {
108108

109109
private int numTestsPerEvictionRun = 3;
110110

111+
private int database = 0;
112+
113+
private String username = null;
114+
111115
public int getNumTestsPerEvictionRun() {
112116
return numTestsPerEvictionRun;
113117
}
@@ -283,4 +287,20 @@ public RetryPolicyFactory getConnectionRetryPolicy() {
283287
return () -> new RetryNTimes(maxRetryAttempts, false);
284288
}
285289
}
290+
291+
public int getDatabase() {
292+
return database;
293+
}
294+
295+
public void setDatabase(int database) {
296+
this.database = database;
297+
}
298+
299+
public String getUsername() {
300+
return username;
301+
}
302+
303+
public void setUsername(String username) {
304+
this.username = username;
305+
}
286306
}

redis-persistence/src/main/java/com/netflix/conductor/redis/config/RedisSentinelConfiguration.java

+19-2
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,33 @@ protected JedisCommands createJedisCommands(
6363
}
6464
// We use the password of the first sentinel host as password and sentinelPassword
6565
String password = getPassword(hostSupplier.getHosts());
66-
if (password != null) {
66+
if (properties.getUsername() != null && password != null) {
6767
return new JedisSentinel(
6868
new JedisSentinelPool(
6969
properties.getClusterName(),
7070
sentinels,
7171
genericObjectPoolConfig,
7272
Protocol.DEFAULT_TIMEOUT,
7373
Protocol.DEFAULT_TIMEOUT,
74+
properties.getUsername(),
7475
password,
75-
Protocol.DEFAULT_DATABASE,
76+
properties.getDatabase(),
77+
null,
78+
Protocol.DEFAULT_TIMEOUT,
79+
Protocol.DEFAULT_TIMEOUT,
80+
properties.getUsername(),
81+
password,
82+
null));
83+
} else if (password != null) {
84+
return new JedisSentinel(
85+
new JedisSentinelPool(
86+
properties.getClusterName(),
87+
sentinels,
88+
genericObjectPoolConfig,
89+
Protocol.DEFAULT_TIMEOUT,
90+
Protocol.DEFAULT_TIMEOUT,
91+
password,
92+
properties.getDatabase(),
7693
null,
7794
Protocol.DEFAULT_TIMEOUT,
7895
Protocol.DEFAULT_TIMEOUT,

redis-persistence/src/main/java/com/netflix/conductor/redis/config/RedisStandaloneConfiguration.java

+15-4
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,29 @@ protected JedisCommands createJedisCommands(
4545
config.setMaxTotal(properties.getMaxConnectionsPerHost());
4646
log.info("Starting conductor server using redis_standalone.");
4747
Host host = hostSupplier.getHosts().get(0);
48-
return new JedisStandalone(getJedisPool(config, host));
48+
return new JedisStandalone(getJedisPool(config, host, properties));
4949
}
5050

51-
private JedisPool getJedisPool(JedisPoolConfig config, Host host) {
52-
if (host.getPassword() != null) {
51+
private JedisPool getJedisPool(JedisPoolConfig config, Host host, RedisProperties properties) {
52+
if (properties.getUsername() != null && host.getPassword() != null) {
5353
log.info("Connecting to Redis Standalone with AUTH");
5454
return new JedisPool(
5555
config,
5656
host.getHostName(),
5757
host.getPort(),
5858
Protocol.DEFAULT_TIMEOUT,
59-
host.getPassword());
59+
properties.getUsername(),
60+
host.getPassword(),
61+
properties.getDatabase());
62+
} else if (host.getPassword() != null) {
63+
log.info("Connecting to Redis Standalone with AUTH");
64+
return new JedisPool(
65+
config,
66+
host.getHostName(),
67+
host.getPort(),
68+
Protocol.DEFAULT_TIMEOUT,
69+
host.getPassword(),
70+
properties.getDatabase());
6071
} else {
6172
return new JedisPool(config, host.getHostName(), host.getPort());
6273
}

0 commit comments

Comments
 (0)