Skip to content

Commit

Permalink
Merge pull request #14 from Anupchat/main
Browse files Browse the repository at this point in the history
Adding Redis ACL support with username
  • Loading branch information
v1r3n authored Dec 23, 2023
2 parents 13e5063 + 7bcbadb commit 9665771
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public QueueRedisProperties(ConductorProperties conductorProperties) {
/** Database number. Defaults to a 0. Can be anywhere from 0 to 15 */
private int database = 0;

/** The username to be used for connecting to redis if using Auth with ACL */
private String username = null;

/**
* The maximum amount of time to wait for a connection to become available from the connection
* pool
Expand Down Expand Up @@ -268,6 +271,14 @@ public void setDatabase(int database) {
this.database = database;
}

public String getUsername() {
return username;
}

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

public String getQueuePrefix() {
String prefix = getQueueNamespacePrefix() + "." + conductorProperties.getStack();
if (getKeyspaceDomain() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,18 @@ protected JedisPool getJedisPoolStandalone(QueueRedisProperties redisProperties)
redisProperties.isSsl());
Host host = hostSupplier.getHosts().get(0);

if (host.getPassword() != null) {
if (redisProperties.getUsername() != null && host.getPassword() != null) {
log.info("Connecting to Redis Standalone with ACL user AUTH");
return new JedisPool(
config,
host.getHostName(),
host.getPort(),
Protocol.DEFAULT_TIMEOUT,
redisProperties.getUsername(),
host.getPassword(),
redisProperties.getDatabase(),
redisProperties.isSsl());
} else if (host.getPassword() != null) {
log.info("Connecting to Redis Standalone with AUTH");
return new JedisPool(
config,
Expand Down Expand Up @@ -136,7 +147,24 @@ public JedisSentinelPool getJedisPoolSentinel(QueueRedisProperties properties) {
}
// 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 JedisSentinelPool(
properties.getClusterName(),
sentinels,
genericObjectPoolConfig,
Protocol.DEFAULT_TIMEOUT,
Protocol.DEFAULT_TIMEOUT,
properties.getUsername(),
password,
properties.getDatabase(),
null,
Protocol.DEFAULT_TIMEOUT,
Protocol.DEFAULT_TIMEOUT,
properties.getUsername(),
password,
null);

} else if (password != null) {
return new JedisSentinelPool(
properties.getClusterName(),
sentinels,
Expand Down

0 comments on commit 9665771

Please sign in to comment.