Skip to content

Commit 0fa36c9

Browse files
authored
fix: [CCPOKR-12770] Redis support for services to start under docker or localhost when running locally. (#3170)
* fix: Add a way to provide different redis host depending on whether it is running inside docker or localhost. * fix: Getting the envar in RedisConfig didn't work so explicitly fetching it in RedisClusterModule and setting the hostname accordingly which works.
1 parent 8a3692a commit 0fa36c9

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

misk-redis/src/main/kotlin/misk/redis/RedisClusterModule.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,15 @@ class RedisClusterModule @JvmOverloads constructor(
9090
//CLIENT SETINFO is only supported in Redis v7.2+
9191
.clientSetInfoConfig(ClientSetInfoConfig.DISABLED)
9292
.build()
93+
94+
// We want to support services running both under docker and localhost when running locally and this is a way to support that.
95+
// If a hostname is provided, it will always take precedence over the environment variable.
96+
val redisHost = replicationGroup.configuration_endpoint.hostname?.takeUnless { it.isNullOrBlank() } ?: System.getenv("REDIS_HOST") ?: "127.0.0.1"
97+
9398
return JedisCluster(
9499
setOf(
95100
HostAndPort(
96-
replicationGroup.configuration_endpoint.hostname,
101+
redisHost,
97102
replicationGroup.configuration_endpoint.port
98103
)
99104
),

misk-redis/src/main/kotlin/misk/redis/RedisConfig.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ data class RedisReplicationGroupConfig @JvmOverloads constructor(
1818
)
1919

2020
data class RedisNodeConfig(
21-
val hostname: String,
21+
val hostname: String?,
2222
val port: Int
2323
)

0 commit comments

Comments
 (0)