Skip to content

Commit 2a9fb06

Browse files
Redis ACL authentication (#124)
Signed-off-by: Thibault Meyer <meyer.thibault@gmail.com>
1 parent 176ddfa commit 2a9fb06

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

voidframework-redis/src/main/java/dev/voidframework/redis/module/JedisResourceProvider.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class JedisResourceProvider implements Provider<Jedis> {
3232
private static final String CONFIGURATION_KEY_CONNECTION_POOL_MAXIMUM_WAIT = "voidframework.redis.connPool.maximumWait";
3333
private static final String CONFIGURATION_KEY_HOST = "voidframework.redis.host";
3434
private static final String CONFIGURATION_KEY_PORT = "voidframework.redis.port";
35+
private static final String CONFIGURATION_KEY_USERNAME = "voidframework.redis.username";
3536
private static final String CONFIGURATION_KEY_PASSWORD = "voidframework.redis.password";
3637

3738
private final Config configuration;
@@ -62,6 +63,7 @@ public Jedis get() {
6263
final Duration maximumWait = this.configuration.getDuration(CONFIGURATION_KEY_CONNECTION_POOL_MAXIMUM_WAIT);
6364
final String host = this.configuration.getString(CONFIGURATION_KEY_HOST);
6465
final int port = this.configuration.getInt(CONFIGURATION_KEY_PORT);
66+
final String username = this.configuration.getString(CONFIGURATION_KEY_USERNAME);
6567
final String password = this.configuration.getString(CONFIGURATION_KEY_PASSWORD);
6668

6769
// Checks configuration
@@ -91,7 +93,11 @@ public Jedis get() {
9193
jedisPoolConfig.setMaxWait(maximumWait);
9294

9395
if (StringUtils.isNotBlank(password)) {
94-
this.jedisPool = new JedisPool(jedisPoolConfig, host, port, (int) connectionTimeout, password);
96+
if (StringUtils.isBlank(username)) {
97+
this.jedisPool = new JedisPool(jedisPoolConfig, host, port, (int) connectionTimeout, password);
98+
} else {
99+
this.jedisPool = new JedisPool(jedisPoolConfig, host, port, (int) connectionTimeout, username, password);
100+
}
95101
} else {
96102
this.jedisPool = new JedisPool(jedisPoolConfig, host, port, (int) connectionTimeout);
97103
}

voidframework-redis/src/main/resources/reference.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ voidframework {
1717
port = 6379
1818

1919
# Redis authentication
20+
# Note: username only works with Redis 6+ ACL-based authentication
21+
username = ""
2022
password = ""
2123

2224
# Defines the database to use by default. Must be a valid # number. Check

voidframework-redis/src/test/java/com/voidframework/redis/RedisTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ private Redis createRedisInstance(final String hostname, final int port) {
630630
voidframework.core.runInDevMode = true
631631
voidframework.redis.host = "%s"
632632
voidframework.redis.port = %d
633+
voidframework.redis.username = ""
633634
voidframework.redis.password = ""
634635
voidframework.redis.defaultDatabase = 0
635636
voidframework.redis.connPool.connectionTimeout = "2000 ms"

0 commit comments

Comments
 (0)