diff --git a/modules/core/src/main/scala/dev/profunktor/fs2redis/codecs/Codecs.scala b/modules/core/src/main/scala/dev/profunktor/redis4cats/codecs/Codecs.scala similarity index 100% rename from modules/core/src/main/scala/dev/profunktor/fs2redis/codecs/Codecs.scala rename to modules/core/src/main/scala/dev/profunktor/redis4cats/codecs/Codecs.scala diff --git a/modules/core/src/main/scala/dev/profunktor/fs2redis/codecs/splits/SplitEpi.scala b/modules/core/src/main/scala/dev/profunktor/redis4cats/codecs/splits/SplitEpi.scala similarity index 100% rename from modules/core/src/main/scala/dev/profunktor/fs2redis/codecs/splits/SplitEpi.scala rename to modules/core/src/main/scala/dev/profunktor/redis4cats/codecs/splits/SplitEpi.scala diff --git a/modules/core/src/main/scala/dev/profunktor/fs2redis/codecs/splits/SplitMono.scala b/modules/core/src/main/scala/dev/profunktor/redis4cats/codecs/splits/SplitMono.scala similarity index 100% rename from modules/core/src/main/scala/dev/profunktor/fs2redis/codecs/splits/SplitMono.scala rename to modules/core/src/main/scala/dev/profunktor/redis4cats/codecs/splits/SplitMono.scala diff --git a/modules/core/src/main/scala/dev/profunktor/fs2redis/codecs/splits/package.scala b/modules/core/src/main/scala/dev/profunktor/redis4cats/codecs/splits/package.scala similarity index 100% rename from modules/core/src/main/scala/dev/profunktor/fs2redis/codecs/splits/package.scala rename to modules/core/src/main/scala/dev/profunktor/redis4cats/codecs/splits/package.scala diff --git a/modules/core/src/main/scala/dev/profunktor/fs2redis/connection/RedisClient.scala b/modules/core/src/main/scala/dev/profunktor/redis4cats/connection/RedisClient.scala similarity index 100% rename from modules/core/src/main/scala/dev/profunktor/fs2redis/connection/RedisClient.scala rename to modules/core/src/main/scala/dev/profunktor/redis4cats/connection/RedisClient.scala diff --git a/modules/core/src/main/scala/dev/profunktor/fs2redis/connection/RedisClusterClient.scala b/modules/core/src/main/scala/dev/profunktor/redis4cats/connection/RedisClusterClient.scala similarity index 100% rename from modules/core/src/main/scala/dev/profunktor/fs2redis/connection/RedisClusterClient.scala rename to modules/core/src/main/scala/dev/profunktor/redis4cats/connection/RedisClusterClient.scala diff --git a/modules/core/src/main/scala/dev/profunktor/fs2redis/connection/RedisConnection.scala b/modules/core/src/main/scala/dev/profunktor/redis4cats/connection/RedisConnection.scala similarity index 100% rename from modules/core/src/main/scala/dev/profunktor/fs2redis/connection/RedisConnection.scala rename to modules/core/src/main/scala/dev/profunktor/redis4cats/connection/RedisConnection.scala diff --git a/modules/core/src/main/scala/dev/profunktor/fs2redis/connection/RedisMasterSlave.scala b/modules/core/src/main/scala/dev/profunktor/redis4cats/connection/RedisMasterSlave.scala similarity index 100% rename from modules/core/src/main/scala/dev/profunktor/fs2redis/connection/RedisMasterSlave.scala rename to modules/core/src/main/scala/dev/profunktor/redis4cats/connection/RedisMasterSlave.scala diff --git a/modules/core/src/main/scala/dev/profunktor/fs2redis/connection/RedisURI.scala b/modules/core/src/main/scala/dev/profunktor/redis4cats/connection/RedisURI.scala similarity index 100% rename from modules/core/src/main/scala/dev/profunktor/fs2redis/connection/RedisURI.scala rename to modules/core/src/main/scala/dev/profunktor/redis4cats/connection/RedisURI.scala diff --git a/modules/core/src/main/scala/dev/profunktor/fs2redis/domain.scala b/modules/core/src/main/scala/dev/profunktor/redis4cats/domain.scala similarity index 71% rename from modules/core/src/main/scala/dev/profunktor/fs2redis/domain.scala rename to modules/core/src/main/scala/dev/profunktor/redis4cats/domain.scala index 207d4a94..3d6f02a8 100644 --- a/modules/core/src/main/scala/dev/profunktor/fs2redis/domain.scala +++ b/modules/core/src/main/scala/dev/profunktor/redis4cats/domain.scala @@ -16,9 +16,9 @@ package dev.profunktor.redis4cats -import io.lettuce.core.{ RedisClient => JRedisClient } +import io.lettuce.core.{ RedisClient => JRedisClient, ReadFrom => JReadFrom } import io.lettuce.core.cluster.{ RedisClusterClient => JClusterClient } -import io.lettuce.core.codec.{ RedisCodec => JRedisCodec, ToByteBufEncoder } +import io.lettuce.core.codec.{ RedisCodec => JRedisCodec, StringCodec, ToByteBufEncoder } import io.lettuce.core.masterslave.StatefulRedisMasterSlaveConnection object domain { @@ -40,9 +40,9 @@ object domain { extends RedisMasterSlaveConnection[K, V] trait RedisChannel[K] { - def value: K + def underlying: K } - case class LiveChannel[K](value: K) extends RedisChannel[K] + case class LiveChannel[K](underlying: K) extends RedisChannel[K] type JCodec[K, V] = JRedisCodec[K, V] with ToByteBufEncoder[K, V] @@ -51,4 +51,17 @@ object domain { } case class LiveRedisCodec[K, V](underlying: JCodec[K, V]) extends RedisCodec[K, V] + object RedisCodec { + val Ascii = LiveRedisCodec(StringCodec.ASCII) + val Utf8 = LiveRedisCodec(StringCodec.UTF8) + } + + object ReadFrom { + val Master = JReadFrom.MASTER + val MasterPreferred = JReadFrom.MASTER_PREFERRED + val Nearest = JReadFrom.NEAREST + val Slave = JReadFrom.SLAVE + val SlavePreferred = JReadFrom.SLAVE_PREFERRED + } + } diff --git a/modules/core/src/main/scala/dev/profunktor/fs2redis/effect/JRFuture.scala b/modules/core/src/main/scala/dev/profunktor/redis4cats/effect/JRFuture.scala similarity index 100% rename from modules/core/src/main/scala/dev/profunktor/fs2redis/effect/JRFuture.scala rename to modules/core/src/main/scala/dev/profunktor/redis4cats/effect/JRFuture.scala diff --git a/modules/core/src/main/scala/dev/profunktor/fs2redis/effect/Log.scala b/modules/core/src/main/scala/dev/profunktor/redis4cats/effect/Log.scala similarity index 100% rename from modules/core/src/main/scala/dev/profunktor/fs2redis/effect/Log.scala rename to modules/core/src/main/scala/dev/profunktor/redis4cats/effect/Log.scala diff --git a/modules/core/src/test/scala/dev/profunktor/fs2redis/codecs/SplitEpiTests.scala b/modules/core/src/test/scala/dev/profunktor/redis4cats/codecs/SplitEpiTests.scala similarity index 100% rename from modules/core/src/test/scala/dev/profunktor/fs2redis/codecs/SplitEpiTests.scala rename to modules/core/src/test/scala/dev/profunktor/redis4cats/codecs/SplitEpiTests.scala diff --git a/modules/core/src/test/scala/dev/profunktor/fs2redis/codecs/SplitMonoTests.scala b/modules/core/src/test/scala/dev/profunktor/redis4cats/codecs/SplitMonoTests.scala similarity index 100% rename from modules/core/src/test/scala/dev/profunktor/fs2redis/codecs/SplitMonoTests.scala rename to modules/core/src/test/scala/dev/profunktor/redis4cats/codecs/SplitMonoTests.scala diff --git a/modules/core/src/test/scala/dev/profunktor/fs2redis/codecs/SplitMorphismTest.scala b/modules/core/src/test/scala/dev/profunktor/redis4cats/codecs/SplitMorphismTest.scala similarity index 100% rename from modules/core/src/test/scala/dev/profunktor/fs2redis/codecs/SplitMorphismTest.scala rename to modules/core/src/test/scala/dev/profunktor/redis4cats/codecs/SplitMorphismTest.scala diff --git a/modules/core/src/test/scala/dev/profunktor/fs2redis/codecs/laws/SplitEpiLaws.scala b/modules/core/src/test/scala/dev/profunktor/redis4cats/codecs/laws/SplitEpiLaws.scala similarity index 100% rename from modules/core/src/test/scala/dev/profunktor/fs2redis/codecs/laws/SplitEpiLaws.scala rename to modules/core/src/test/scala/dev/profunktor/redis4cats/codecs/laws/SplitEpiLaws.scala diff --git a/modules/core/src/test/scala/dev/profunktor/fs2redis/codecs/laws/SplitMonoLaws.scala b/modules/core/src/test/scala/dev/profunktor/redis4cats/codecs/laws/SplitMonoLaws.scala similarity index 100% rename from modules/core/src/test/scala/dev/profunktor/fs2redis/codecs/laws/SplitMonoLaws.scala rename to modules/core/src/test/scala/dev/profunktor/redis4cats/codecs/laws/SplitMonoLaws.scala diff --git a/modules/core/src/test/scala/dev/profunktor/fs2redis/effect/JRFutureSpec.scala b/modules/core/src/test/scala/dev/profunktor/redis4cats/effect/JRFutureSpec.scala similarity index 100% rename from modules/core/src/test/scala/dev/profunktor/fs2redis/effect/JRFutureSpec.scala rename to modules/core/src/test/scala/dev/profunktor/redis4cats/effect/JRFutureSpec.scala diff --git a/modules/effects/src/main/scala/dev/profunktor/fs2redis/RedisTransaction.scala b/modules/effects/src/main/scala/dev/profunktor/fs2redis/RedisTransaction.scala deleted file mode 100644 index 49ee9070..00000000 --- a/modules/effects/src/main/scala/dev/profunktor/fs2redis/RedisTransaction.scala +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2018-2019 ProfunKtor - * - * 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 dev.profunktor.redis4cats - -import cats.effect._ -import cats.effect.implicits._ -import cats.implicits._ -import dev.profunktor.redis4cats.algebra._ -import dev.profunktor.redis4cats.effect.Log - -case class RedisTransaction[F[_]: Log: Sync, K, V]( - cmd: RedisCommands[F, K, V] -) { - def run[A](fa: F[A]): F[A] = - Log[F].info("Transaction started") *> - cmd.multi.bracketCase(_ => fa) { - case (_, ExitCase.Completed) => cmd.exec *> Log[F].info("Transaction completed") - case (_, ExitCase.Error(e)) => cmd.discard *> Log[F].error(s"Transaction failed: ${e.getMessage}") - case (_, ExitCase.Canceled) => cmd.discard *> Log[F].error("Transaction canceled") - } -} diff --git a/modules/effects/src/main/scala/dev/profunktor/fs2redis/algebra/connection.scala b/modules/effects/src/main/scala/dev/profunktor/redis4cats/algebra/connection.scala similarity index 100% rename from modules/effects/src/main/scala/dev/profunktor/fs2redis/algebra/connection.scala rename to modules/effects/src/main/scala/dev/profunktor/redis4cats/algebra/connection.scala diff --git a/modules/effects/src/main/scala/dev/profunktor/fs2redis/algebra/geo.scala b/modules/effects/src/main/scala/dev/profunktor/redis4cats/algebra/geo.scala similarity index 100% rename from modules/effects/src/main/scala/dev/profunktor/fs2redis/algebra/geo.scala rename to modules/effects/src/main/scala/dev/profunktor/redis4cats/algebra/geo.scala diff --git a/modules/effects/src/main/scala/dev/profunktor/fs2redis/algebra/hashes.scala b/modules/effects/src/main/scala/dev/profunktor/redis4cats/algebra/hashes.scala similarity index 100% rename from modules/effects/src/main/scala/dev/profunktor/fs2redis/algebra/hashes.scala rename to modules/effects/src/main/scala/dev/profunktor/redis4cats/algebra/hashes.scala diff --git a/modules/effects/src/main/scala/dev/profunktor/fs2redis/algebra/lists.scala b/modules/effects/src/main/scala/dev/profunktor/redis4cats/algebra/lists.scala similarity index 100% rename from modules/effects/src/main/scala/dev/profunktor/fs2redis/algebra/lists.scala rename to modules/effects/src/main/scala/dev/profunktor/redis4cats/algebra/lists.scala diff --git a/modules/effects/src/main/scala/dev/profunktor/fs2redis/algebra/redis.scala b/modules/effects/src/main/scala/dev/profunktor/redis4cats/algebra/redis.scala similarity index 100% rename from modules/effects/src/main/scala/dev/profunktor/fs2redis/algebra/redis.scala rename to modules/effects/src/main/scala/dev/profunktor/redis4cats/algebra/redis.scala diff --git a/modules/effects/src/main/scala/dev/profunktor/fs2redis/algebra/server.scala b/modules/effects/src/main/scala/dev/profunktor/redis4cats/algebra/server.scala similarity index 100% rename from modules/effects/src/main/scala/dev/profunktor/fs2redis/algebra/server.scala rename to modules/effects/src/main/scala/dev/profunktor/redis4cats/algebra/server.scala diff --git a/modules/effects/src/main/scala/dev/profunktor/fs2redis/algebra/sets.scala b/modules/effects/src/main/scala/dev/profunktor/redis4cats/algebra/sets.scala similarity index 100% rename from modules/effects/src/main/scala/dev/profunktor/fs2redis/algebra/sets.scala rename to modules/effects/src/main/scala/dev/profunktor/redis4cats/algebra/sets.scala diff --git a/modules/effects/src/main/scala/dev/profunktor/fs2redis/algebra/sortedsets.scala b/modules/effects/src/main/scala/dev/profunktor/redis4cats/algebra/sortedsets.scala similarity index 100% rename from modules/effects/src/main/scala/dev/profunktor/fs2redis/algebra/sortedsets.scala rename to modules/effects/src/main/scala/dev/profunktor/redis4cats/algebra/sortedsets.scala diff --git a/modules/effects/src/main/scala/dev/profunktor/fs2redis/algebra/strings.scala b/modules/effects/src/main/scala/dev/profunktor/redis4cats/algebra/strings.scala similarity index 100% rename from modules/effects/src/main/scala/dev/profunktor/fs2redis/algebra/strings.scala rename to modules/effects/src/main/scala/dev/profunktor/redis4cats/algebra/strings.scala diff --git a/modules/effects/src/main/scala/dev/profunktor/fs2redis/algebra/transaction.scala b/modules/effects/src/main/scala/dev/profunktor/redis4cats/algebra/transaction.scala similarity index 100% rename from modules/effects/src/main/scala/dev/profunktor/fs2redis/algebra/transaction.scala rename to modules/effects/src/main/scala/dev/profunktor/redis4cats/algebra/transaction.scala diff --git a/modules/effects/src/main/scala/dev/profunktor/fs2redis/effects.scala b/modules/effects/src/main/scala/dev/profunktor/redis4cats/effects.scala similarity index 100% rename from modules/effects/src/main/scala/dev/profunktor/fs2redis/effects.scala rename to modules/effects/src/main/scala/dev/profunktor/redis4cats/effects.scala diff --git a/modules/effects/src/main/scala/dev/profunktor/fs2redis/interpreter/Redis.scala b/modules/effects/src/main/scala/dev/profunktor/redis4cats/interpreter/Redis.scala similarity index 99% rename from modules/effects/src/main/scala/dev/profunktor/fs2redis/interpreter/Redis.scala rename to modules/effects/src/main/scala/dev/profunktor/redis4cats/interpreter/Redis.scala index 269e5b55..9ab54639 100644 --- a/modules/effects/src/main/scala/dev/profunktor/fs2redis/interpreter/Redis.scala +++ b/modules/effects/src/main/scala/dev/profunktor/redis4cats/interpreter/Redis.scala @@ -15,7 +15,6 @@ */ package dev.profunktor.redis4cats.interpreter -import java.util.concurrent.TimeUnit import cats.effect._ import cats.implicits._ @@ -25,13 +24,10 @@ import dev.profunktor.redis4cats.domain._ import dev.profunktor.redis4cats.effect.{ JRFuture, Log } import dev.profunktor.redis4cats.effects._ import io.lettuce.core.{ Limit => JLimit, Range => JRange, RedisURI => JRedisURI } -import io.lettuce.core.{ GeoRadiusStoreArgs, GeoWithin, ScoredValue } +import io.lettuce.core.{ GeoArgs, GeoRadiusStoreArgs, GeoWithin, ScoredValue, ZAddArgs, ZStoreArgs } import io.lettuce.core.cluster.api.async.RedisClusterAsyncCommands - +import java.util.concurrent.TimeUnit import scala.concurrent.duration.FiniteDuration -import io.lettuce.core.GeoArgs -import io.lettuce.core.ZAddArgs -import io.lettuce.core.ZStoreArgs object Redis { diff --git a/modules/effects/src/main/scala/dev/profunktor/fs2redis/transactions.scala b/modules/effects/src/main/scala/dev/profunktor/redis4cats/transactions.scala similarity index 93% rename from modules/effects/src/main/scala/dev/profunktor/fs2redis/transactions.scala rename to modules/effects/src/main/scala/dev/profunktor/redis4cats/transactions.scala index fa59c949..c089489a 100644 --- a/modules/effects/src/main/scala/dev/profunktor/fs2redis/transactions.scala +++ b/modules/effects/src/main/scala/dev/profunktor/redis4cats/transactions.scala @@ -24,10 +24,10 @@ import dev.profunktor.redis4cats.effect.Log object transactions { - case class RedisTransaction[F[_]: Log: Sync, K, V, A]( + case class RedisTransaction[F[_]: Log: Sync, K, V]( cmd: RedisCommands[F, K, V] ) { - def run(fa: F[A]): F[A] = + def run[A](fa: F[A]): F[A] = Log[F].info("Transaction started") *> cmd.multi.bracketCase(_ => fa) { case (_, ExitCase.Completed) => cmd.exec *> Log[F].info("Transaction completed") diff --git a/modules/examples/src/main/scala/dev/profunktor/fs2redis/Demo.scala b/modules/examples/src/main/scala/dev/profunktor/redis4cats/Demo.scala similarity index 84% rename from modules/examples/src/main/scala/dev/profunktor/fs2redis/Demo.scala rename to modules/examples/src/main/scala/dev/profunktor/redis4cats/Demo.scala index 824002ef..84f2acc4 100644 --- a/modules/examples/src/main/scala/dev/profunktor/fs2redis/Demo.scala +++ b/modules/examples/src/main/scala/dev/profunktor/redis4cats/Demo.scala @@ -19,14 +19,13 @@ package dev.profunktor.redis4cats import cats.effect.IO import dev.profunktor.redis4cats.codecs.Codecs import dev.profunktor.redis4cats.codecs.splits._ -import dev.profunktor.redis4cats.domain.{ LiveRedisCodec, RedisCodec } -import io.lettuce.core.codec.StringCodec +import dev.profunktor.redis4cats.domain.RedisCodec object Demo { val redisURI: String = "redis://localhost" val redisClusterURI: String = "redis://localhost:30001" - val stringCodec: RedisCodec[String, String] = LiveRedisCodec(StringCodec.UTF8) + val stringCodec: RedisCodec[String, String] = RedisCodec.Utf8 val longCodec: RedisCodec[String, Long] = Codecs.derive[String, Long](stringCodec, stringLongEpi) def putStrLn[A](a: A): IO[Unit] = IO(println(a)) diff --git a/modules/examples/src/main/scala/dev/profunktor/fs2redis/LoggerIOApp.scala b/modules/examples/src/main/scala/dev/profunktor/redis4cats/LoggerIOApp.scala similarity index 100% rename from modules/examples/src/main/scala/dev/profunktor/fs2redis/LoggerIOApp.scala rename to modules/examples/src/main/scala/dev/profunktor/redis4cats/LoggerIOApp.scala diff --git a/modules/examples/src/main/scala/dev/profunktor/fs2redis/Fs2PubSubDemo.scala b/modules/examples/src/main/scala/dev/profunktor/redis4cats/PubSubDemo.scala similarity index 100% rename from modules/examples/src/main/scala/dev/profunktor/fs2redis/Fs2PubSubDemo.scala rename to modules/examples/src/main/scala/dev/profunktor/redis4cats/PubSubDemo.scala diff --git a/modules/examples/src/main/scala/dev/profunktor/fs2redis/Fs2PublisherDemo.scala b/modules/examples/src/main/scala/dev/profunktor/redis4cats/PublisherDemo.scala similarity index 100% rename from modules/examples/src/main/scala/dev/profunktor/fs2redis/Fs2PublisherDemo.scala rename to modules/examples/src/main/scala/dev/profunktor/redis4cats/PublisherDemo.scala diff --git a/modules/examples/src/main/scala/dev/profunktor/fs2redis/Fs2RedisClusterStringsDemo.scala b/modules/examples/src/main/scala/dev/profunktor/redis4cats/RedisClusterStringsDemo.scala similarity index 100% rename from modules/examples/src/main/scala/dev/profunktor/fs2redis/Fs2RedisClusterStringsDemo.scala rename to modules/examples/src/main/scala/dev/profunktor/redis4cats/RedisClusterStringsDemo.scala diff --git a/modules/examples/src/main/scala/dev/profunktor/fs2redis/Fs2RedisGeoDemo.scala b/modules/examples/src/main/scala/dev/profunktor/redis4cats/RedisGeoDemo.scala similarity index 100% rename from modules/examples/src/main/scala/dev/profunktor/fs2redis/Fs2RedisGeoDemo.scala rename to modules/examples/src/main/scala/dev/profunktor/redis4cats/RedisGeoDemo.scala diff --git a/modules/examples/src/main/scala/dev/profunktor/fs2redis/Fs2RedisHashesDemo.scala b/modules/examples/src/main/scala/dev/profunktor/redis4cats/RedisHashesDemo.scala similarity index 100% rename from modules/examples/src/main/scala/dev/profunktor/fs2redis/Fs2RedisHashesDemo.scala rename to modules/examples/src/main/scala/dev/profunktor/redis4cats/RedisHashesDemo.scala diff --git a/modules/examples/src/main/scala/dev/profunktor/fs2redis/Fs2RedisListsDemo.scala b/modules/examples/src/main/scala/dev/profunktor/redis4cats/RedisListsDemo.scala similarity index 100% rename from modules/examples/src/main/scala/dev/profunktor/fs2redis/Fs2RedisListsDemo.scala rename to modules/examples/src/main/scala/dev/profunktor/redis4cats/RedisListsDemo.scala diff --git a/modules/examples/src/main/scala/dev/profunktor/fs2redis/Fs2RedisMasterSlaveStringsDemo.scala b/modules/examples/src/main/scala/dev/profunktor/redis4cats/RedisMasterSlaveStringsDemo.scala similarity index 92% rename from modules/examples/src/main/scala/dev/profunktor/fs2redis/Fs2RedisMasterSlaveStringsDemo.scala rename to modules/examples/src/main/scala/dev/profunktor/redis4cats/RedisMasterSlaveStringsDemo.scala index bbc21b68..5a0fbc10 100644 --- a/modules/examples/src/main/scala/dev/profunktor/fs2redis/Fs2RedisMasterSlaveStringsDemo.scala +++ b/modules/examples/src/main/scala/dev/profunktor/redis4cats/RedisMasterSlaveStringsDemo.scala @@ -18,10 +18,9 @@ package dev.profunktor.redis4cats import cats.effect.{ IO, Resource } import dev.profunktor.redis4cats.connection._ -import dev.profunktor.redis4cats.domain.RedisMasterSlaveConnection +import dev.profunktor.redis4cats.domain.{ ReadFrom, RedisMasterSlaveConnection } import dev.profunktor.redis4cats.effect.Log import dev.profunktor.redis4cats.interpreter.Redis -import io.lettuce.core.{ ReadFrom => JReadFrom } object Fs2RedisMasterSlaveStringsDemo extends LoggerIOApp { @@ -35,7 +34,7 @@ object Fs2RedisMasterSlaveStringsDemo extends LoggerIOApp { val connection: Resource[IO, RedisMasterSlaveConnection[String, String]] = Resource.liftF(RedisURI.make[IO](redisURI)).flatMap { uri => - RedisMasterSlave[IO, String, String](stringCodec, uri)(Some(JReadFrom.MASTER_PREFERRED)) + RedisMasterSlave[IO, String, String](stringCodec, uri)(Some(ReadFrom.MasterPreferred)) } connection diff --git a/modules/examples/src/main/scala/dev/profunktor/fs2redis/Fs2RedisSetsDemo.scala b/modules/examples/src/main/scala/dev/profunktor/redis4cats/RedisSetsDemo.scala similarity index 100% rename from modules/examples/src/main/scala/dev/profunktor/fs2redis/Fs2RedisSetsDemo.scala rename to modules/examples/src/main/scala/dev/profunktor/redis4cats/RedisSetsDemo.scala diff --git a/modules/examples/src/main/scala/dev/profunktor/fs2redis/Fs2RedisSortedSetsDemo.scala b/modules/examples/src/main/scala/dev/profunktor/redis4cats/RedisSortedSetsDemo.scala similarity index 100% rename from modules/examples/src/main/scala/dev/profunktor/fs2redis/Fs2RedisSortedSetsDemo.scala rename to modules/examples/src/main/scala/dev/profunktor/redis4cats/RedisSortedSetsDemo.scala diff --git a/modules/examples/src/main/scala/dev/profunktor/fs2redis/Fs2RedisStringsDemo.scala b/modules/examples/src/main/scala/dev/profunktor/redis4cats/RedisStringsDemo.scala similarity index 100% rename from modules/examples/src/main/scala/dev/profunktor/fs2redis/Fs2RedisStringsDemo.scala rename to modules/examples/src/main/scala/dev/profunktor/redis4cats/RedisStringsDemo.scala diff --git a/modules/examples/src/main/scala/dev/profunktor/fs2redis/Fs2RedisTransactionsDemo.scala b/modules/examples/src/main/scala/dev/profunktor/redis4cats/RedisTransactionsDemo.scala similarity index 95% rename from modules/examples/src/main/scala/dev/profunktor/fs2redis/Fs2RedisTransactionsDemo.scala rename to modules/examples/src/main/scala/dev/profunktor/redis4cats/RedisTransactionsDemo.scala index 2ddd900f..9175417f 100644 --- a/modules/examples/src/main/scala/dev/profunktor/fs2redis/Fs2RedisTransactionsDemo.scala +++ b/modules/examples/src/main/scala/dev/profunktor/redis4cats/RedisTransactionsDemo.scala @@ -23,8 +23,9 @@ import dev.profunktor.redis4cats.algebra.RedisCommands import dev.profunktor.redis4cats.connection._ import dev.profunktor.redis4cats.effect.Log import dev.profunktor.redis4cats.interpreter.Redis +import dev.profunktor.redis4cats.transactions._ -object Fs2RedisTransactionsDemo extends LoggerIOApp { +object RedisTransactionsDemo extends LoggerIOApp { import Demo._ diff --git a/modules/examples/src/main/scala/dev/profunktor/fs2redis/Fs2StreamingDemo.scala b/modules/examples/src/main/scala/dev/profunktor/redis4cats/StreamingDemo.scala similarity index 100% rename from modules/examples/src/main/scala/dev/profunktor/fs2redis/Fs2StreamingDemo.scala rename to modules/examples/src/main/scala/dev/profunktor/redis4cats/StreamingDemo.scala diff --git a/modules/log4cats/src/main/scala/dev/profunktor/fs2redis/log4cats.scala b/modules/log4cats/src/main/scala/dev/profunktor/redis4cats/log4cats.scala similarity index 100% rename from modules/log4cats/src/main/scala/dev/profunktor/fs2redis/log4cats.scala rename to modules/log4cats/src/main/scala/dev/profunktor/redis4cats/log4cats.scala diff --git a/modules/streams/src/main/scala/dev/profunktor/fs2redis/algebra/pubsub.scala b/modules/streams/src/main/scala/dev/profunktor/redis4cats/algebra/pubsub.scala similarity index 100% rename from modules/streams/src/main/scala/dev/profunktor/fs2redis/algebra/pubsub.scala rename to modules/streams/src/main/scala/dev/profunktor/redis4cats/algebra/pubsub.scala diff --git a/modules/streams/src/main/scala/dev/profunktor/fs2redis/algebra/streams.scala b/modules/streams/src/main/scala/dev/profunktor/redis4cats/algebra/streams.scala similarity index 100% rename from modules/streams/src/main/scala/dev/profunktor/fs2redis/algebra/streams.scala rename to modules/streams/src/main/scala/dev/profunktor/redis4cats/algebra/streams.scala diff --git a/modules/streams/src/main/scala/dev/profunktor/fs2redis/interpreter/pubsub/LivePubSubCommands.scala b/modules/streams/src/main/scala/dev/profunktor/redis4cats/interpreter/pubsub/LivePubSubCommands.scala similarity index 89% rename from modules/streams/src/main/scala/dev/profunktor/fs2redis/interpreter/pubsub/LivePubSubCommands.scala rename to modules/streams/src/main/scala/dev/profunktor/redis4cats/interpreter/pubsub/LivePubSubCommands.scala index a6cbbc46..1956cad8 100644 --- a/modules/streams/src/main/scala/dev/profunktor/fs2redis/interpreter/pubsub/LivePubSubCommands.scala +++ b/modules/streams/src/main/scala/dev/profunktor/redis4cats/interpreter/pubsub/LivePubSubCommands.scala @@ -45,12 +45,10 @@ class LivePubSubCommands[F[_]: ConcurrentEffect: ContextShift: Log, K, V]( override def publish(channel: RedisChannel[K]): Stream[F, V] => Stream[F, Unit] = _.evalMap { message => - val getOrCreateTopicListener = PubSubInternals[F, K, V](state, subConnection) - for { - st <- state.get - _ <- getOrCreateTopicListener(channel)(st) - _ <- JRFuture { Sync[F].delay(pubConnection.async().publish(channel.value, message)) } - } yield () + state.get.flatMap { st => + PubSubInternals[F, K, V](state, subConnection).apply(channel)(st) *> + JRFuture { Sync[F].delay(pubConnection.async().publish(channel.underlying, message)) } + }.void } override def pubSubChannels: Stream[F, List[K]] = diff --git a/modules/streams/src/main/scala/dev/profunktor/fs2redis/interpreter/pubsub/LivePubSubStats.scala b/modules/streams/src/main/scala/dev/profunktor/redis4cats/interpreter/pubsub/LivePubSubStats.scala similarity index 84% rename from modules/streams/src/main/scala/dev/profunktor/fs2redis/interpreter/pubsub/LivePubSubStats.scala rename to modules/streams/src/main/scala/dev/profunktor/redis4cats/interpreter/pubsub/LivePubSubStats.scala index e58c9067..2bccc46a 100644 --- a/modules/streams/src/main/scala/dev/profunktor/fs2redis/interpreter/pubsub/LivePubSubStats.scala +++ b/modules/streams/src/main/scala/dev/profunktor/redis4cats/interpreter/pubsub/LivePubSubStats.scala @@ -17,8 +17,7 @@ package dev.profunktor.redis4cats.interpreter.pubsub import cats.effect.{ Concurrent, ContextShift, Sync } -import cats.syntax.flatMap._ -import cats.syntax.functor._ +import cats.syntax.all._ import dev.profunktor.redis4cats.algebra.PubSubStats import dev.profunktor.redis4cats.domain._ import dev.profunktor.redis4cats.streams.Subscription @@ -44,10 +43,9 @@ class LivePubSubStats[F[_]: Concurrent: ContextShift, K, V]( override def pubSubSubscriptions(channels: List[RedisChannel[K]]): Stream[F, List[Subscription[K]]] = Stream.eval { - for { - kv <- JRFuture(Sync[F].delay(pubConnection.async().pubsubNumsub(channels.map(_.value): _*))) - rs <- Sync[F].delay(kv.asScala.toList.map { case (k, n) => Subscription(LiveChannel[K](k), n) }) - } yield rs + JRFuture(Sync[F].delay(pubConnection.async().pubsubNumsub(channels.map(_.underlying): _*))).flatMap { kv => + Sync[F].delay(kv.asScala.toList.map { case (k, n) => Subscription(LiveChannel[K](k), n) }) + } } } diff --git a/modules/streams/src/main/scala/dev/profunktor/fs2redis/interpreter/pubsub/PubSub.scala b/modules/streams/src/main/scala/dev/profunktor/redis4cats/interpreter/pubsub/PubSub.scala similarity index 95% rename from modules/streams/src/main/scala/dev/profunktor/fs2redis/interpreter/pubsub/PubSub.scala rename to modules/streams/src/main/scala/dev/profunktor/redis4cats/interpreter/pubsub/PubSub.scala index 396e09e0..80e64ba7 100644 --- a/modules/streams/src/main/scala/dev/profunktor/fs2redis/interpreter/pubsub/PubSub.scala +++ b/modules/streams/src/main/scala/dev/profunktor/redis4cats/interpreter/pubsub/PubSub.scala @@ -92,11 +92,9 @@ object PubSub { uri: JRedisURI ): Stream[F, SubscribeCommands[Stream[F, ?], K, V]] = { val (acquire, release) = acquireAndRelease[F, K, V](client, codec, uri) - - for { - state <- Stream.eval(Ref.of(Map.empty[K, Topic[F, Option[V]]])) - sConn <- Stream.bracket(acquire)(release) - } yield new Subscriber[F, K, V](state, sConn) + Stream.eval(Ref.of(Map.empty[K, Topic[F, Option[V]]])).flatMap { st => + Stream.bracket(acquire)(release).map(new Subscriber(st, _)) + } } } diff --git a/modules/streams/src/main/scala/dev/profunktor/fs2redis/interpreter/pubsub/Publisher.scala b/modules/streams/src/main/scala/dev/profunktor/redis4cats/interpreter/pubsub/Publisher.scala similarity index 98% rename from modules/streams/src/main/scala/dev/profunktor/fs2redis/interpreter/pubsub/Publisher.scala rename to modules/streams/src/main/scala/dev/profunktor/redis4cats/interpreter/pubsub/Publisher.scala index 9808e2db..d0526078 100644 --- a/modules/streams/src/main/scala/dev/profunktor/fs2redis/interpreter/pubsub/Publisher.scala +++ b/modules/streams/src/main/scala/dev/profunktor/redis4cats/interpreter/pubsub/Publisher.scala @@ -32,7 +32,7 @@ class Publisher[F[_]: ConcurrentEffect: ContextShift, K, V](pubConnection: State override def publish(channel: RedisChannel[K]): Stream[F, V] => Stream[F, Unit] = _.evalMap { message => - JRFuture { Sync[F].delay(pubConnection.async().publish(channel.value, message)) }.void + JRFuture { Sync[F].delay(pubConnection.async().publish(channel.underlying, message)) }.void } override def pubSubChannels: Stream[F, List[K]] = diff --git a/modules/streams/src/main/scala/dev/profunktor/fs2redis/interpreter/pubsub/Subscriber.scala b/modules/streams/src/main/scala/dev/profunktor/redis4cats/interpreter/pubsub/Subscriber.scala similarity index 78% rename from modules/streams/src/main/scala/dev/profunktor/fs2redis/interpreter/pubsub/Subscriber.scala rename to modules/streams/src/main/scala/dev/profunktor/redis4cats/interpreter/pubsub/Subscriber.scala index 4d9f1fad..f6022e0b 100644 --- a/modules/streams/src/main/scala/dev/profunktor/fs2redis/interpreter/pubsub/Subscriber.scala +++ b/modules/streams/src/main/scala/dev/profunktor/redis4cats/interpreter/pubsub/Subscriber.scala @@ -24,7 +24,6 @@ import dev.profunktor.redis4cats.interpreter.pubsub.internals.{ PubSubInternals, import dev.profunktor.redis4cats.domain.RedisChannel import dev.profunktor.redis4cats.effect.{ JRFuture, Log } import fs2.Stream -import fs2.concurrent.Topic import io.lettuce.core.pubsub.StatefulRedisPubSubConnection class Subscriber[F[_]: ConcurrentEffect: ContextShift: Log, K, V]( @@ -32,21 +31,19 @@ class Subscriber[F[_]: ConcurrentEffect: ContextShift: Log, K, V]( subConnection: StatefulRedisPubSubConnection[K, V] ) extends SubscribeCommands[Stream[F, ?], K, V] { - override def subscribe(channel: RedisChannel[K]): Stream[F, V] = { - val getOrCreateTopicListener = PubSubInternals[F, K, V](state, subConnection) - val setup: F[Topic[F, Option[V]]] = - for { - st <- state.get - topic <- getOrCreateTopicListener(channel)(st) - _ <- JRFuture(Sync[F].delay(subConnection.async().subscribe(channel.value))) - } yield topic - - Stream.eval(setup).flatMap(_.subscribe(500).unNone) - } + override def subscribe(channel: RedisChannel[K]): Stream[F, V] = + Stream + .eval( + state.get.flatMap { st => + PubSubInternals[F, K, V](state, subConnection).apply(channel)(st) <* + JRFuture(Sync[F].delay(subConnection.async().subscribe(channel.underlying))) + } + ) + .flatMap(_.subscribe(500).unNone) override def unsubscribe(channel: RedisChannel[K]): Stream[F, Unit] = Stream.eval { - JRFuture(Sync[F].delay(subConnection.async().unsubscribe(channel.value))).void + JRFuture(Sync[F].delay(subConnection.async().unsubscribe(channel.underlying))).void } } diff --git a/modules/streams/src/main/scala/dev/profunktor/fs2redis/interpreter/pubsub/internals/PubSubInternals.scala b/modules/streams/src/main/scala/dev/profunktor/redis4cats/interpreter/pubsub/internals/PubSubInternals.scala similarity index 84% rename from modules/streams/src/main/scala/dev/profunktor/fs2redis/interpreter/pubsub/internals/PubSubInternals.scala rename to modules/streams/src/main/scala/dev/profunktor/redis4cats/interpreter/pubsub/internals/PubSubInternals.scala index bfe123a4..73a679e1 100644 --- a/modules/streams/src/main/scala/dev/profunktor/fs2redis/interpreter/pubsub/internals/PubSubInternals.scala +++ b/modules/streams/src/main/scala/dev/profunktor/redis4cats/interpreter/pubsub/internals/PubSubInternals.scala @@ -33,7 +33,7 @@ object PubSubInternals { ): RedisPubSubListener[K, V] = new RedisPubSubListener[K, V] { override def message(ch: K, msg: V): Unit = - if (ch == channel.value) { + if (ch == channel.underlying) { topic.publish1(Option(msg)).toIO.unsafeRunAsync(_ => ()) } override def message(pattern: K, channel: K, message: V): Unit = this.message(channel, message) @@ -47,15 +47,14 @@ object PubSubInternals { state: Ref[F, PubSubState[F, K, V]], subConnection: StatefulRedisPubSubConnection[K, V] )(implicit F: ConcurrentEffect[F], L: Log[F]): GetOrCreateTopicListener[F, K, V] = { channel => st => - st.get(channel.value) + st.get(channel.underlying) .fold { - for { - topic <- Topic[F, Option[V]](None) - listener = defaultListener(channel, topic) - _ <- L.info(s"Creating listener for channel: $channel") - _ <- F.delay(subConnection.addListener(listener)) - _ <- state.update(_.updated(channel.value, topic)) - } yield topic + Topic[F, Option[V]](None).flatTap { topic => + val listener = defaultListener(channel, topic) + L.info(s"Creating listener for channel: $channel") *> + F.delay(subConnection.addListener(listener)) *> + state.update(_.updated(channel.underlying, topic)) + } }(F.pure) } diff --git a/modules/streams/src/main/scala/dev/profunktor/fs2redis/interpreter/pubsub/internals/package.scala b/modules/streams/src/main/scala/dev/profunktor/redis4cats/interpreter/pubsub/internals/package.scala similarity index 100% rename from modules/streams/src/main/scala/dev/profunktor/fs2redis/interpreter/pubsub/internals/package.scala rename to modules/streams/src/main/scala/dev/profunktor/redis4cats/interpreter/pubsub/internals/package.scala diff --git a/modules/streams/src/main/scala/dev/profunktor/fs2redis/interpreter/streams/Fs2RawStreaming.scala b/modules/streams/src/main/scala/dev/profunktor/redis4cats/interpreter/streams/Fs2RawStreaming.scala similarity index 98% rename from modules/streams/src/main/scala/dev/profunktor/fs2redis/interpreter/streams/Fs2RawStreaming.scala rename to modules/streams/src/main/scala/dev/profunktor/redis4cats/interpreter/streams/Fs2RawStreaming.scala index b6c9282d..0abde917 100644 --- a/modules/streams/src/main/scala/dev/profunktor/fs2redis/interpreter/streams/Fs2RawStreaming.scala +++ b/modules/streams/src/main/scala/dev/profunktor/redis4cats/interpreter/streams/Fs2RawStreaming.scala @@ -33,7 +33,7 @@ private[streams] class RedisRawStreaming[F[_]: Concurrent: ContextShift, K, V]( override def xAdd(key: K, body: Map[K, V]): F[MessageId] = JRFuture { Sync[F].delay(client.async().xadd(key, body.asJava)) - }.map(MessageId.apply) + }.map(MessageId) override def xRead(streams: Set[StreamingOffset[K]]): F[List[StreamingMessageWithId[K, V]]] = { val offsets = streams.map(s => StreamOffset.from(s.key, s.offset)).toSeq diff --git a/modules/streams/src/main/scala/dev/profunktor/fs2redis/interpreter/streams/Fs2Streaming.scala b/modules/streams/src/main/scala/dev/profunktor/redis4cats/interpreter/streams/Fs2Streaming.scala similarity index 98% rename from modules/streams/src/main/scala/dev/profunktor/fs2redis/interpreter/streams/Fs2Streaming.scala rename to modules/streams/src/main/scala/dev/profunktor/redis4cats/interpreter/streams/Fs2Streaming.scala index c4c96bc3..56532fdc 100644 --- a/modules/streams/src/main/scala/dev/profunktor/fs2redis/interpreter/streams/Fs2Streaming.scala +++ b/modules/streams/src/main/scala/dev/profunktor/redis4cats/interpreter/streams/Fs2Streaming.scala @@ -39,7 +39,7 @@ object RedisStream { .fromConnectionFuture { Sync[F].delay(client.underlying.connectAsync[K, V](codec.underlying, uri)) } - .map(c => new RedisRawStreaming(c)) + .map(new RedisRawStreaming(_)) val release: RedisRawStreaming[F, K, V] => F[Unit] = c => JRFuture.fromCompletableFuture(Sync[F].delay(c.client.closeAsync())) *> diff --git a/modules/streams/src/main/scala/dev/profunktor/fs2redis/streams.scala b/modules/streams/src/main/scala/dev/profunktor/redis4cats/streams.scala similarity index 100% rename from modules/streams/src/main/scala/dev/profunktor/fs2redis/streams.scala rename to modules/streams/src/main/scala/dev/profunktor/redis4cats/streams.scala diff --git a/modules/test-support/src/main/scala/dev/profunktor/fs2redis/DockerRedis.scala b/modules/test-support/src/main/scala/dev/profunktor/redis4cats/DockerRedis.scala similarity index 90% rename from modules/test-support/src/main/scala/dev/profunktor/fs2redis/DockerRedis.scala rename to modules/test-support/src/main/scala/dev/profunktor/redis4cats/DockerRedis.scala index b252a93f..f66a7d2b 100644 --- a/modules/test-support/src/main/scala/dev/profunktor/fs2redis/DockerRedis.scala +++ b/modules/test-support/src/main/scala/dev/profunktor/redis4cats/DockerRedis.scala @@ -16,17 +16,14 @@ package dev.profunktor.redis4cats -import cats.effect.{ Clock, ContextShift, IO, Timer } +import cats.effect._ import cats.syntax.apply._ import cats.syntax.functor._ import dev.profunktor.redis4cats.algebra._ -import dev.profunktor.redis4cats.connection.RedisClient -import dev.profunktor.redis4cats.domain.{ LiveRedisCodec, RedisCodec } +import dev.profunktor.redis4cats.connection.{ RedisClient, RedisURI } +import dev.profunktor.redis4cats.domain.RedisCodec import dev.profunktor.redis4cats.interpreter.Redis -import io.lettuce.core.{ RedisURI => JRedisURI } -import io.lettuce.core.codec.{ StringCodec => JStringCodec } import org.scalatest.{ BeforeAndAfterAll, BeforeAndAfterEach, Suite } - import scala.concurrent.{ ExecutionContext, SyncVar } import scala.sys.process.{ Process, ProcessLogger } import scala.util.Random @@ -44,8 +41,6 @@ trait DockerRedis extends BeforeAndAfterAll with BeforeAndAfterEach { self: Suit lazy val redisPort: Int = 6379 - lazy val redisUri: JRedisURI = JRedisURI.create("redis://localhost") - private var dockerInstanceId: Option[String] = None implicit val cs: ContextShift[IO] = IO.contextShift(ExecutionContext.global) @@ -71,13 +66,14 @@ trait DockerRedis extends BeforeAndAfterAll with BeforeAndAfterEach { self: Suit dockerInstanceId.foreach(stopRedis(_, clearContainers)) } - private val stringCodec = LiveRedisCodec(JStringCodec.UTF8) + private val stringCodec = RedisCodec.Utf8 private def mkRedis[K, V](codec: RedisCodec[K, V]) = - RedisClient[IO](redisUri) - .flatMap { client => - Redis[IO, K, V](client, codec, redisUri) - } + for { + uri <- Resource.liftF(RedisURI.make[IO]("redis://localhost")) + client <- RedisClient[IO](uri) + redis <- Redis[IO, K, V](client, codec, uri) + } yield redis def withAbstractRedis[A, K, V](f: RedisCommands[IO, K, V] => IO[A])(codec: RedisCodec[K, V]): Unit = mkRedis(codec).use(f).void.unsafeRunSync() diff --git a/modules/test-support/src/main/scala/dev/profunktor/fs2redis/RedisClusterTest.scala b/modules/test-support/src/main/scala/dev/profunktor/redis4cats/RedisClusterTest.scala similarity index 80% rename from modules/test-support/src/main/scala/dev/profunktor/fs2redis/RedisClusterTest.scala rename to modules/test-support/src/main/scala/dev/profunktor/redis4cats/RedisClusterTest.scala index 86c85934..a3717cc1 100644 --- a/modules/test-support/src/main/scala/dev/profunktor/fs2redis/RedisClusterTest.scala +++ b/modules/test-support/src/main/scala/dev/profunktor/redis4cats/RedisClusterTest.scala @@ -16,15 +16,12 @@ package dev.profunktor.redis4cats -import cats.effect.{ Clock, ContextShift, IO, Timer } -import cats.syntax.apply._ -import cats.syntax.functor._ +import cats.effect._ +import cats.implicits._ import dev.profunktor.redis4cats.algebra._ -import dev.profunktor.redis4cats.connection.RedisClusterClient -import dev.profunktor.redis4cats.domain.{ LiveRedisCodec, RedisCodec } +import dev.profunktor.redis4cats.connection.{ RedisClusterClient, RedisURI } +import dev.profunktor.redis4cats.domain.RedisCodec import dev.profunktor.redis4cats.interpreter.Redis -import io.lettuce.core.{ RedisURI => JRedisURI } -import io.lettuce.core.codec.{ StringCodec => JStringCodec } import org.scalatest.{ BeforeAndAfterAll, BeforeAndAfterEach, Suite } import scala.concurrent.ExecutionContext @@ -42,17 +39,17 @@ trait RedisClusterTest extends BeforeAndAfterAll with BeforeAndAfterEach { self: lazy val firstPort = 30001 lazy val lastPort = 30006 - lazy val redisUri: List[JRedisURI] = List( + lazy val redisUri = List( "redis://localhost:30001", "redis://localhost:30002", "redis://localhost:30003" - ).map(JRedisURI.create) + ).traverse(RedisURI.make[IO](_)) implicit val cts: ContextShift[IO] = IO.contextShift(ExecutionContext.global) implicit val timer: Timer[IO] = IO.timer(ExecutionContext.global) implicit val clock: Clock[IO] = timer.clock - private val stringCodec = LiveRedisCodec(JStringCodec.UTF8) + private val stringCodec = RedisCodec.Utf8 private var dockerInstanceId: Option[String] = None @@ -75,11 +72,12 @@ trait RedisClusterTest extends BeforeAndAfterAll with BeforeAndAfterEach { self: dockerInstanceId.foreach(stopRedis(_, clearContainers)) } - private def mkRedisCluster[K, V](codec: RedisCodec[K, V]) = - RedisClusterClient[IO](redisUri: _*) - .flatMap { client => - Redis.cluster[IO, K, V](client, codec) - } + private def mkRedisCluster[K, V](codec: RedisCodec[K, V]): Resource[IO, RedisCommands[IO, K, V]] = + for { + uris <- Resource.liftF(redisUri) + client <- RedisClusterClient[IO](uris: _*) + cluster <- Redis.cluster[IO, K, V](client, codec) + } yield cluster def withAbstractRedisCluster[A, K, V]( f: RedisCommands[IO, K, V] => IO[A] diff --git a/modules/test-support/src/main/scala/dev/profunktor/fs2redis/testLogger.scala b/modules/test-support/src/main/scala/dev/profunktor/redis4cats/testLogger.scala similarity index 100% rename from modules/test-support/src/main/scala/dev/profunktor/fs2redis/testLogger.scala rename to modules/test-support/src/main/scala/dev/profunktor/redis4cats/testLogger.scala diff --git a/modules/tests/src/test/scala/dev/profunktor/fs2redis/Fs2RedisClusterSpec.scala b/modules/tests/src/test/scala/dev/profunktor/redis4cats/Fs2RedisClusterSpec.scala similarity index 100% rename from modules/tests/src/test/scala/dev/profunktor/fs2redis/Fs2RedisClusterSpec.scala rename to modules/tests/src/test/scala/dev/profunktor/redis4cats/Fs2RedisClusterSpec.scala diff --git a/modules/tests/src/test/scala/dev/profunktor/fs2redis/Fs2RedisSpec.scala b/modules/tests/src/test/scala/dev/profunktor/redis4cats/Fs2RedisSpec.scala similarity index 100% rename from modules/tests/src/test/scala/dev/profunktor/fs2redis/Fs2RedisSpec.scala rename to modules/tests/src/test/scala/dev/profunktor/redis4cats/Fs2RedisSpec.scala diff --git a/modules/tests/src/test/scala/dev/profunktor/fs2redis/Fs2TestScenarios.scala b/modules/tests/src/test/scala/dev/profunktor/redis4cats/Fs2TestScenarios.scala similarity index 99% rename from modules/tests/src/test/scala/dev/profunktor/fs2redis/Fs2TestScenarios.scala rename to modules/tests/src/test/scala/dev/profunktor/redis4cats/Fs2TestScenarios.scala index 2dd4a6b6..b511fe8c 100644 --- a/modules/tests/src/test/scala/dev/profunktor/fs2redis/Fs2TestScenarios.scala +++ b/modules/tests/src/test/scala/dev/profunktor/redis4cats/Fs2TestScenarios.scala @@ -21,6 +21,7 @@ import cats.implicits._ import dev.profunktor.redis4cats.algebra._ import dev.profunktor.redis4cats.effect.Log import dev.profunktor.redis4cats.effects._ +import dev.profunktor.redis4cats.transactions._ import io.lettuce.core.GeoArgs trait Fs2TestScenarios { diff --git a/site/src/main/tut/effects/index.md b/site/src/main/tut/effects/index.md index c428e830..a6f85abc 100644 --- a/site/src/main/tut/effects/index.md +++ b/site/src/main/tut/effects/index.md @@ -28,7 +28,7 @@ def apply[F[_]](uri: RedisURI): Resource[F, RedisClient] ### Logger -In order to create a client and/or connection you must provide a `Log` instance that the library uses for internal logging. You could either create your own or use `log4cats` (recommended). `fs2-redis` can derive an instance of `Log[F]` if there is an instance of `Logger[F]` in scope, just need to add the extra dependency `fs2-redis-log4cats` and `import dev.profunktor.redis4cats.log4cats._`. +In order to create a client and/or connection you must provide a `Log` instance that the library uses for internal logging. You could either create your own or use `log4cats` (recommended). `redis4cats` can derive an instance of `Log[F]` if there is an instance of `Logger[F]` in scope, just need to add the extra dependency `redis4cats-log4cats` and `import dev.profunktor.redis4cats.log4cats._`. Take a look at the [examples](https://github.com/gvolpe/fs2-redis/blob/master/modules/examples/src/main/scala/dev.profunktor.redis4cats/LoggerIOApp.scala) to find out more. @@ -41,18 +41,16 @@ import cats.effect.{IO, Resource} import cats.syntax.all._ import dev.profunktor.redis4cats.algebra.StringCommands import dev.profunktor.redis4cats.connection.{RedisClient, RedisURI} -import dev.profunktor.redis4cats.domain.{LiveRedisCodec, RedisCodec} +import dev.profunktor.redis4cats.domain.RedisCodec import dev.profunktor.redis4cats.interpreter.Redis import dev.profunktor.redis4cats.log4cats._ -import io.lettuce.core.{ RedisURI => JRedisURI } -import io.lettuce.core.codec.{RedisCodec => JRedisCodec, StringCodec => JStringCodec} import io.chrisdavenport.log4cats.Logger import io.chrisdavenport.log4cats.slf4j.Slf4jLogger implicit val cs = IO.contextShift(scala.concurrent.ExecutionContext.global) implicit val logger: Logger[IO] = Slf4jLogger.unsafeCreate[IO] -val stringCodec: RedisCodec[String, String] = LiveRedisCodec(JStringCodec.UTF8) +val stringCodec: RedisCodec[String, String] = RedisCodec.Utf8 val commandsApi: Resource[IO, StringCommands[IO, String, String]] = for { @@ -89,7 +87,7 @@ The process is a bit different. First of all, you don't need to create a `RedisC ```scala def apply[F[_], K, V](codec: RedisCodec[K, V], uris: JRedisURI*)( - readFrom: Option[JReadFrom] = None): Resource[F, RedisMasterSlaveConnection[K, V]] + readFrom: Option[ReadFrom] = None): Resource[F, RedisMasterSlaveConnection[K, V]] ``` #### Example using the Strings API @@ -100,15 +98,13 @@ import cats.syntax.all._ import dev.profunktor.redis4cats.algebra.StringCommands import dev.profunktor.redis4cats.connection.RedisMasterSlave import dev.profunktor.redis4cats.interpreter.Redis -import dev.profunktor.redis4cats.domain.RedisMasterSlaveConnection -import io.lettuce.core.{ReadFrom => JReadFrom, RedisURI => JRedisURI} -import io.lettuce.core.codec.{RedisCodec => JRedisCodec, StringCodec => JStringCodec} +import dev.profunktor.redis4cats.domain.{ RedisMasterSlaveConnection, ReadFrom } -val stringCodec: RedisCodec[String, String] = LiveRedisCodec(JStringCodec.UTF8) +val stringCodec: RedisCodec[String, String] = RedisCodec.Utf8 val connection: Resource[IO, RedisMasterSlaveConnection[String, String]] = Resource.liftF(RedisURI.make[IO]("redis://localhost")).flatMap { uri => - RedisMasterSlave[IO, String, String](stringCodec, uri)(Some(JReadFrom.MASTER_PREFERRED)) + RedisMasterSlave[IO, String, String](stringCodec, uri)(Some(ReadFrom.MasterPreferred)) } connection.use { conn => diff --git a/site/src/main/tut/streams/pubsub.md b/site/src/main/tut/streams/pubsub.md index b5f21460..cd4b7cee 100644 --- a/site/src/main/tut/streams/pubsub.md +++ b/site/src/main/tut/streams/pubsub.md @@ -56,13 +56,12 @@ When using the `PubSub` interpreter the `publish` function will be defined as a import cats.effect.{ExitCode, IO, IOApp} import cats.syntax.apply._ import dev.profunktor.redis4cats.connection.{ RedisClient, RedisURI } -import dev.profunktor.redis4cats.domain.{ LiveChannel, LiveRedisCodec } +import dev.profunktor.redis4cats.domain.{ LiveChannel, RedisCodec } import dev.profunktor.redis4cats.interpreter.pubsub.PubSub import dev.profunktor.redis4cats.log4cats._ import fs2.{Sink, Stream} import io.chrisdavenport.log4cats.Logger import io.chrisdavenport.log4cats.slf4j.Slf4jLogger -import io.lettuce.core.codec.{ StringCodec => JStringCodec } import scala.concurrent.duration._ import scala.util.Random @@ -71,7 +70,7 @@ object PubSubDemo extends IOApp { implicit val logger: Logger[IO] = Slf4jLogger.unsafeCreate[IO] - private val stringCodec = LiveRedisCodec(JStringCodec.UTF8) + private val stringCodec = RedisCodec.Utf8 private val eventsChannel = LiveChannel("events") private val gamesChannel = LiveChannel("games") diff --git a/site/src/main/tut/streams/streams.md b/site/src/main/tut/streams/streams.md index 674d5f0d..40068285 100644 --- a/site/src/main/tut/streams/streams.md +++ b/site/src/main/tut/streams/streams.md @@ -26,7 +26,7 @@ def mkStreamingConnection[F[_], K, V]( ```scala def mkMasterSlaveConnection[F[_], K, V](codec: RedisCodec[K, V], uris: JRedisURI*)( - readFrom: Option[JReadFrom] = None): Stream[F, Streaming[Stream[F, ?], K, V]] + readFrom: Option[ReadFrom] = None): Stream[F, Streaming[Stream[F, ?], K, V]] ``` #### Cluster connection @@ -59,8 +59,6 @@ import dev.profunktor.redis4cats.streams._ import fs2.Stream import io.chrisdavenport.log4cats.Logger import io.chrisdavenport.log4cats.slf4j.Slf4jLogger -import io.lettuce.core.codec.{ StringCodec => JStringCodec } - import scala.concurrent.ExecutionContext import scala.concurrent.duration._ import scala.util.Random @@ -69,7 +67,7 @@ implicit val timer = IO.timer(ExecutionContext.global) implicit val cs = IO.contextShift(ExecutionContext.global) implicit val logger: Logger[IO] = Slf4jLogger.unsafeCreate[IO] -val stringCodec = LiveRedisCodec(JStringCodec.UTF8) +val stringCodec = RedisCodec.Utf8 def putStrLn(str: String): IO[Unit] = IO(println(str)) diff --git a/site/src/main/tut/transactions.md b/site/src/main/tut/transactions.md index 07fdc1fd..70fdd687 100644 --- a/site/src/main/tut/transactions.md +++ b/site/src/main/tut/transactions.md @@ -39,6 +39,7 @@ val commandsApi: Resource[IO, RedisCommands[IO, String, String]] = { import cats.effect.IO import cats.implicits._ import dev.profunktor.redis4cats._ +import dev.profunktor.redis4cats.transactions._ def putStrLn(str: String): IO[Unit] = IO(println(str))