Skip to content

Commit

Permalink
Eksperiment: Bygg Redis-URI selv for service
Browse files Browse the repository at this point in the history
  • Loading branch information
bjerga committed Jan 16, 2025
1 parent d4ca932 commit bce52ff
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ fun main() {
val rapid = RapidApplication.create(System.getenv())
val aivenRedisConnection =
RedisConnection(
Env.Redis.aivenHost,
Env.Redis.aivenPassword,
Env.Redis.aivenPort,
Env.Redis.aivenUsername,
host = Env.Redis.aivenHost,
port = Env.Redis.aivenPort,
username = Env.Redis.aivenUsername,
password = Env.Redis.aivenPassword,
)
val redisConnection = RedisConnection(Env.Redis.url)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ object Env {

object Redis {
val aivenHost: String = "REDIS_HOST_INNTEKTSMELDING".fromEnv()
val aivenPassword: String = "REDIS_PASSWORD_INNTEKTSMELDING".fromEnv()
val aivenPort: String = "REDIS_PORT_INNTEKTSMELDING".fromEnv()
val aivenPort: Int = "REDIS_PORT_INNTEKTSMELDING".fromEnv().toInt()
val aivenUsername: String = "REDIS_USERNAME_INNTEKTSMELDING".fromEnv()
val aivenPassword: String = "REDIS_PASSWORD_INNTEKTSMELDING".fromEnv()

// val aivenUri: String = "REDIS_URI_INNTEKTSMELDING".fromEnv()
val url: String = "REDIS_URL".fromEnv()
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package no.nav.helsearbeidsgiver.felles.rapidsrivers.redis

import io.lettuce.core.RedisClient
import io.lettuce.core.RedisURI
import io.lettuce.core.api.StatefulRedisConnection
import io.lettuce.core.api.sync.RedisCommands
import no.nav.helsearbeidsgiver.utils.collection.mapValuesNotNull
Expand All @@ -9,11 +10,22 @@ class RedisConnection(
redisUri: String,
) {
constructor(
aivenHost: String,
aivenPassword: String,
aivenPort: String,
aivenUsername: String,
) : this("rediss://$aivenUsername:$aivenPassword@$aivenHost:$aivenPort/0")
host: String,
port: Int,
username: String,
password: String,
) : this(
RedisURI
.builder()
.withSsl(true)
.withHost(host)
.withPort(port)
.withAuthentication(username, password)
.withDatabase(0)
.build()
.toURI()
.toString(),
)

private val client: RedisClient = RedisClient.create(redisUri)
private val connection: StatefulRedisConnection<String, String> = client.connect()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ import no.nav.helsearbeidsgiver.utils.log.logger
private val logger = "helsearbeidsgiver-im-hent-forespoersel-service".logger()

fun main() {
val redisConnection = RedisConnection(Env.redisUri)
val redisConnection =
RedisConnection(
host = Env.redisHost,
port = Env.redisPort,
username = Env.redisUsername,
password = Env.redisPassword,
)

RapidApplication
.create(System.getenv())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ package no.nav.helsearbeidsgiver.inntektsmelding.trengerservice
import no.nav.helsearbeidsgiver.felles.utils.fromEnv

object Env {
val redisUri = "REDIS_URI_INNTEKTSMELDING".fromEnv()
val redisHost: String = "REDIS_HOST_INNTEKTSMELDING".fromEnv()
val redisPort: Int = "REDIS_PORT_INNTEKTSMELDING".fromEnv().toInt()
val redisUsername: String = "REDIS_USERNAME_INNTEKTSMELDING".fromEnv()
val redisPassword: String = "REDIS_PASSWORD_INNTEKTSMELDING".fromEnv()
}

0 comments on commit bce52ff

Please sign in to comment.