From 322f2151b70636c69e3163aa840b3d78f4b3234a Mon Sep 17 00:00:00 2001 From: Jakub Chrobasik Date: Mon, 22 Jan 2024 14:56:22 +0100 Subject: [PATCH] feat: RedisUrl config type --- .../renku/redis/client/RedisQueueClient.scala | 4 ++-- .../io/renku/redis/client/RedisUrl.scala | 24 +++++++++++++++++++ .../renku/redis/client/util/RedisSpec.scala | 9 ++++++- 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 modules/redis-client/src/main/scala/io/renku/redis/client/RedisUrl.scala diff --git a/modules/redis-client/src/main/scala/io/renku/redis/client/RedisQueueClient.scala b/modules/redis-client/src/main/scala/io/renku/redis/client/RedisQueueClient.scala index 6df389b3..b0558a27 100644 --- a/modules/redis-client/src/main/scala/io/renku/redis/client/RedisQueueClient.scala +++ b/modules/redis-client/src/main/scala/io/renku/redis/client/RedisQueueClient.scala @@ -33,9 +33,9 @@ import scodec.bits.ByteVector import scribe.Scribe object RedisQueueClient: - def apply[F[_]: Async: Scribe]: Resource[F, QueueClient[F]] = + def apply[F[_]: Async: Scribe](redisUrl: RedisUrl): Resource[F, QueueClient[F]] = given Log[F] = RedisLogger[F] - RedisClient[F].from("url").map(new RedisQueueClient[F](_)) + RedisClient[F].from(redisUrl.toString).map(new RedisQueueClient[F](_)) class RedisQueueClient[F[_]: Async: Log](client: RedisClient) extends QueueClient[F] { diff --git a/modules/redis-client/src/main/scala/io/renku/redis/client/RedisUrl.scala b/modules/redis-client/src/main/scala/io/renku/redis/client/RedisUrl.scala new file mode 100644 index 00000000..47885f3d --- /dev/null +++ b/modules/redis-client/src/main/scala/io/renku/redis/client/RedisUrl.scala @@ -0,0 +1,24 @@ +/* + * Copyright 2024 Swiss Data Science Center (SDSC) + * A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and + * Eidgenössische Technische Hochschule Zürich (ETHZ). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.renku.redis.client + +opaque type RedisUrl = String +object RedisUrl { + def apply(v: String): RedisUrl = new RedisUrl(v) +} diff --git a/modules/redis-client/src/test/scala/io/renku/redis/client/util/RedisSpec.scala b/modules/redis-client/src/test/scala/io/renku/redis/client/util/RedisSpec.scala index d8d2451d..57c73913 100644 --- a/modules/redis-client/src/test/scala/io/renku/redis/client/util/RedisSpec.scala +++ b/modules/redis-client/src/test/scala/io/renku/redis/client/util/RedisSpec.scala @@ -19,11 +19,13 @@ package io.renku.redis.client.util import cats.effect.* +import cats.syntax.all.* import dev.profunktor.redis4cats.connection.RedisClient import dev.profunktor.redis4cats.data.RedisCodec import dev.profunktor.redis4cats.effect.Log.Stdout.instance import dev.profunktor.redis4cats.effect.MkRedis.forAsync import dev.profunktor.redis4cats.{Redis, RedisCommands} +import io.lettuce.core.RedisConnectionException import io.renku.queue.client.QueueClient import io.renku.redis.client.RedisQueueClient @@ -41,7 +43,12 @@ trait RedisSpec: val withRedisClient: RedisFixture = new RedisFixture: def apply(): Resource[IO, RedisClient] = - RedisClient[IO].from(server.url) + RedisClient[IO] + .from(server.url) + .recoverWith { + case _: RedisConnectionException => apply() + case ex => Resource.raiseError[IO, RedisClient, Throwable](ex) + } override def asRedisCommands(): Resource[IO, RedisCommands[IO, String, String]] = apply().flatMap(createRedisCommands)