Skip to content

Commit bdf924d

Browse files
committed
feat: add password support for Redis configuration
Extend Redis configuration to include an optional password field (`password`) in global, local, and internal config classes. Update `RedisApi` to utilize the password when building the Redis URI.
1 parent be8a30d commit bdf924d

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

src/main/kotlin/dev/slne/redis/RedisApi.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,11 @@ class RedisApi private constructor(
162162
require(isFrozen()) { "Redis client must be frozen before connecting" }
163163
require(!isConnected()) { "Redis client already initialized" }
164164

165-
val redisURI = RedisURI.create(config.host, config.port)
165+
val redisURI = RedisURI.builder().apply {
166+
withHost(config.host)
167+
withPort(config.port)
168+
config.password?.let { withPassword(it) }
169+
}.build()
166170
redisClient = RedisClient.create(redisURI)
167171

168172
connection = redisClient.connect()

src/main/kotlin/dev/slne/redis/config/GlobalConfig.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ import kotlin.io.path.div
99
@ConfigSerializable
1010
internal data class GlobalConfig(
1111
val host: String = "localhost",
12-
val port: Int = 6379
12+
val port: Int = 6379,
13+
val password: String? = null
1314
) {
1415

1516
fun toInternal() = InternalConfig(
1617
host = host,
17-
port = port
18+
port = port,
19+
password = password
1820
)
1921

2022
companion object {

src/main/kotlin/dev/slne/redis/config/InternalConfig.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import java.nio.file.Path
44

55
internal data class InternalConfig(
66
val host: String = "localhost",
7-
val port: Int = 6379
7+
val port: Int = 6379,
8+
val password: String? = null
89
) {
910

1011
companion object {

src/main/kotlin/dev/slne/redis/config/LocalConfig.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ internal data class LocalConfig(
1414
@ConfigSerializable
1515
data class Local(
1616
val host: String = "localhost",
17-
val port: Int = 6379
17+
val port: Int = 6379,
18+
val password: String? = null
1819
)
1920

2021
fun toInternal() = InternalConfig(
2122
host = local.host,
22-
port = local.port
23+
port = local.port,
24+
password = local.password
2325
)
2426

2527
companion object {

0 commit comments

Comments
 (0)