Skip to content

Commit

Permalink
feat: RedisUrl config type
Browse files Browse the repository at this point in the history
  • Loading branch information
jachro committed Jan 22, 2024
1 parent 4eae845 commit 322f215
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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] {

Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down

0 comments on commit 322f215

Please sign in to comment.