未验证 提交 b19d2381 编写于 作者: D Dejan Mijić 提交者: GitHub

Tweak visibility (#757)

上级 4242806b
......@@ -122,7 +122,7 @@ object ClusterExecutor {
ZIO
.collectFirst(addresses) { address =>
connectToCluster(address).foldZIO(
error => ZIO.logError(s"The connection to cluster has been failed, $error").as(None),
error => ZIO.logError(s"The connection to cluster failed. Cause: $error").as(None),
cc => ZIO.logInfo("The connection to cluster has been established").as(Some(cc))
)
}
......
......@@ -31,10 +31,7 @@ trait Redis
with api.SortedSets
with api.Streams
with api.Scripting
with api.Cluster {
def codec: BinaryCodec
def executor: RedisExecutor
}
with api.Cluster
object Redis {
lazy val layer: URLayer[RedisExecutor with BinaryCodec, Redis] =
......
......@@ -19,6 +19,6 @@ package zio.redis
import zio.schema.codec.BinaryCodec
private[redis] trait RedisEnvironment {
def codec: BinaryCodec
def executor: RedisExecutor
protected def codec: BinaryCodec
protected def executor: RedisExecutor
}
......@@ -34,7 +34,7 @@ trait Cluster extends RedisEnvironment {
* @return
* the Unit value.
*/
def asking: IO[RedisError, Unit] =
final def asking: IO[RedisError, Unit] =
AskingCommand(codec, executor).run(())
/**
......@@ -43,7 +43,7 @@ trait Cluster extends RedisEnvironment {
* @return
* details about which cluster
*/
def slots: IO[RedisError, Chunk[Partition]] = {
final def slots: IO[RedisError, Chunk[Partition]] = {
val command = RedisCommand(ClusterSlots, NoInput, ChunkOutput(ClusterPartitionOutput), codec, executor)
command.run(())
}
......@@ -56,7 +56,7 @@ trait Cluster extends RedisEnvironment {
* @return
* the Unit value.
*/
def setSlotStable(slot: Slot): IO[RedisError, Unit] = {
final def setSlotStable(slot: Slot): IO[RedisError, Unit] = {
val command =
RedisCommand(ClusterSetSlots, Tuple2(LongInput, ArbitraryInput[String]()), UnitOutput, codec, executor)
command.run((slot.number, Stable.stringify))
......@@ -73,7 +73,7 @@ trait Cluster extends RedisEnvironment {
* @return
* the Unit value.
*/
def setSlotMigrating(slot: Slot, nodeId: String): IO[RedisError, Unit] = {
final def setSlotMigrating(slot: Slot, nodeId: String): IO[RedisError, Unit] = {
val command = RedisCommand(
ClusterSetSlots,
Tuple3(LongInput, ArbitraryInput[String](), ArbitraryInput[String]()),
......@@ -95,7 +95,7 @@ trait Cluster extends RedisEnvironment {
* @return
* the Unit value.
*/
def setSlotImporting(slot: Slot, nodeId: String): IO[RedisError, Unit] = {
final def setSlotImporting(slot: Slot, nodeId: String): IO[RedisError, Unit] = {
val command = RedisCommand(
ClusterSetSlots,
Tuple3(LongInput, ArbitraryInput[String](), ArbitraryInput[String]()),
......@@ -117,7 +117,7 @@ trait Cluster extends RedisEnvironment {
* @return
* the Unit value.
*/
def setSlotNode(slot: Slot, nodeId: String): IO[RedisError, Unit] = {
final def setSlotNode(slot: Slot, nodeId: String): IO[RedisError, Unit] = {
val command = RedisCommand(
ClusterSetSlots,
Tuple3(LongInput, ArbitraryInput[String](), ArbitraryInput[String]()),
......
......@@ -38,7 +38,7 @@ trait Scripting extends RedisEnvironment {
* redis protocol value that is converted from the Lua type. You have to write decoder that would convert redis
* protocol value to a suitable type for your app
*/
def eval[K: Input, A: Input](
final def eval[K: Input, A: Input](
script: String,
keys: Chunk[K],
args: Chunk[A]
......@@ -63,7 +63,7 @@ trait Scripting extends RedisEnvironment {
* redis protocol value that is converted from the Lua type. You have to write decoder that would convert redis
* protocol value to a suitable type for your app
*/
def evalSha[K: Input, A: Input](
final def evalSha[K: Input, A: Input](
sha1: String,
keys: Chunk[K],
args: Chunk[A]
......@@ -82,7 +82,7 @@ trait Scripting extends RedisEnvironment {
* @return
* the Unit value.
*/
def scriptDebug(mode: DebugMode): IO[RedisError, Unit] = {
final def scriptDebug(mode: DebugMode): IO[RedisError, Unit] = {
val command = RedisCommand(ScriptDebug, ScriptDebugInput, UnitOutput, codec, executor)
command.run(mode)
}
......@@ -98,7 +98,7 @@ trait Scripting extends RedisEnvironment {
* for every corresponding SHA1 digest of a script that actually exists in the script cache, an true is returned,
* otherwise false is returned.
*/
def scriptExists(sha1: String, sha1s: String*): IO[RedisError, Chunk[Boolean]] = {
final def scriptExists(sha1: String, sha1s: String*): IO[RedisError, Chunk[Boolean]] = {
val command = RedisCommand(ScriptExists, NonEmptyList(StringInput), ChunkOutput(BoolOutput), codec, executor)
command.run((sha1, sha1s.toList))
}
......@@ -112,7 +112,7 @@ trait Scripting extends RedisEnvironment {
* @return
* the Unit value.
*/
def scriptFlush(mode: Option[FlushMode] = None): IO[RedisError, Unit] = {
final def scriptFlush(mode: Option[FlushMode] = None): IO[RedisError, Unit] = {
val command = RedisCommand(ScriptFlush, OptionalInput(ScriptFlushInput), UnitOutput, codec, executor)
command.run(mode)
}
......@@ -123,7 +123,7 @@ trait Scripting extends RedisEnvironment {
* @return
* the Unit value.
*/
def scriptKill: IO[RedisError, Unit] = {
final def scriptKill: IO[RedisError, Unit] = {
val command = RedisCommand(ScriptKill, NoInput, UnitOutput, codec, executor)
command.run(())
}
......@@ -137,7 +137,7 @@ trait Scripting extends RedisEnvironment {
* @return
* the SHA1 digest of the script added into the script cache.
*/
def scriptLoad(script: String): IO[RedisError, String] = {
final def scriptLoad(script: String): IO[RedisError, String] = {
val command = RedisCommand(ScriptLoad, StringInput, MultiStringOutput, codec, executor)
command.run(script)
}
......
......@@ -347,19 +347,19 @@ trait Sets extends RedisEnvironment {
}
private[redis] object Sets {
val SAdd = "SADD"
val SCard = "SCARD"
val SDiff = "SDIFF"
val SDiffStore = "SDIFFSTORE"
val SInter = "SINTER"
val SInterStore = "SINTERSTORE"
val SIsMember = "SISMEMBER"
val SMembers = "SMEMBERS"
val SMove = "SMOVE"
val SPop = "SPOP"
val SRandMember = "SRANDMEMBER"
val SRem = "SREM"
val SScan = "SSCAN"
val SUnion = "SUNION"
val SUnionStore = "SUNIONSTORE"
final val SAdd = "SADD"
final val SCard = "SCARD"
final val SDiff = "SDIFF"
final val SDiffStore = "SDIFFSTORE"
final val SInter = "SINTER"
final val SInterStore = "SINTERSTORE"
final val SIsMember = "SISMEMBER"
final val SMembers = "SMEMBERS"
final val SMove = "SMOVE"
final val SPop = "SPOP"
final val SRandMember = "SRANDMEMBER"
final val SRem = "SREM"
final val SScan = "SSCAN"
final val SUnion = "SUNION"
final val SUnionStore = "SUNIONSTORE"
}
......@@ -1149,7 +1149,7 @@ trait SortedSets extends RedisEnvironment {
*/
final def zMScore[K: Schema](key: K, keys: K*): IO[RedisError, Chunk[Option[Double]]] = {
val command = RedisCommand(
Zmscore,
ZMScore,
NonEmptyList(ArbitraryInput[K]()),
ChunkOutput(OptionalOutput(DoubleOutput)),
codec,
......@@ -1245,6 +1245,7 @@ private[redis] object SortedSets {
final val ZInter = "ZINTER"
final val ZInterStore = "ZINTERSTORE"
final val ZLexCount = "ZLEXCOUNT"
final val ZMScore = "ZMSCORE"
final val ZPopMax = "ZPOPMAX"
final val ZPopMin = "ZPOPMIN"
final val ZRange = "ZRANGE"
......@@ -1263,6 +1264,5 @@ private[redis] object SortedSets {
final val ZScore = "ZSCORE"
final val ZUnion = "ZUNION"
final val ZUnionStore = "ZUNIONSTORE"
final val Zmscore = "ZMSCORE"
final val ZRandMember = "ZRANDMEMBER"
}
package zio.redis
import zio._
import zio.test.TestAspect._
import zio.test._
import zio.{Chunk, Layer, ZLayer}
object ApiSpec
extends ConnectionSpec
......@@ -19,54 +19,46 @@ object ApiSpec
with ClusterSpec {
def spec: Spec[TestEnvironment, Any] =
suite("Redis commands")(
Node.Suite.provideLayerShared(Node.Layer) @@ sequential @@ withLiveEnvironment,
Cluster.Suite.provideLayerShared(Cluster.Layer) @@ sequential @@ withLiveEnvironment
)
private object Node {
val Suite: Spec[Redis, Any] =
suite("Node Executor")(
connectionSuite,
keysSuite,
listSuite,
setsSuite,
sortedSetsSuite,
stringsSuite,
geoSuite,
hyperLogLogSuite,
hashSuite,
streamsSuite,
scriptingSpec
)
val Layer: Layer[Any, Redis] = ZLayer.make[Redis](RedisExecutor.local.orDie, ZLayer.succeed(codec), Redis.layer)
}
suite("Redis commands")(clusterSuite, singleNodeSuite) @@ sequential @@ withLiveEnvironment
private object Cluster {
val Suite: Spec[Redis, Any] =
suite("Cluster Executor")(
connectionSuite,
keysSuite,
listSuite,
stringsSuite,
hashSuite,
setsSuite,
sortedSetsSuite,
hyperLogLogSuite,
geoSuite,
streamsSuite @@ clusterExecutorUnsupported,
scriptingSpec @@ clusterExecutorUnsupported,
clusterSpec
).filterAnnotations(TestAnnotation.tagged)(t => !t.contains(BaseSpec.ClusterExecutorUnsupported)).get
val Layer: Layer[Any, Redis] =
ZLayer.make[Redis](
ZLayer.succeed(RedisClusterConfig(Chunk(RedisUri("localhost", 5000)))),
ClusterExecutor.layer,
ZLayer.succeed(codec),
Redis.layer
)
}
private val singleNodeSuite =
suite("Single node executor")(
connectionSuite,
keysSuite,
listSuite,
setsSuite,
sortedSetsSuite,
stringsSuite,
geoSuite,
hyperLogLogSuite,
hashSuite,
streamsSuite,
scriptingSpec
).provideShared(
RedisExecutor.local,
Redis.layer,
ZLayer.succeed(codec)
)
private val clusterSuite =
suite("Cluster executor")(
connectionSuite,
keysSuite,
listSuite,
stringsSuite,
hashSuite,
setsSuite,
sortedSetsSuite,
hyperLogLogSuite,
geoSuite,
streamsSuite @@ clusterExecutorUnsupported,
scriptingSpec @@ clusterExecutorUnsupported,
clusterSpec
).provideShared(
ClusterExecutor.layer,
Redis.layer,
ZLayer.succeed(codec),
ZLayer.succeed(RedisClusterConfig(Chunk(RedisUri("localhost", 5000))))
).filterNotTags(_.contains(BaseSpec.ClusterExecutorUnsupported))
.getOrElse(Spec.empty)
}
......@@ -2,19 +2,16 @@ package zio.redis
import zio._
import zio.schema.codec.{BinaryCodec, ProtobufCodec}
import zio.test.TestAspect.tag
import zio.test.TestAspect.{fibers, silentLogging, tag, timeout}
import zio.test._
import java.time.Instant
import java.util.UUID
trait BaseSpec extends ZIOSpecDefault {
implicit val codec: BinaryCodec = ProtobufCodec
override def aspects: Chunk[TestAspectAtLeastR[Live]] =
Chunk.succeed(TestAspect.timeout(10.seconds))
def instantOf(millis: Long): UIO[Instant] = ZIO.succeed(Instant.now().plusMillis(millis))
Chunk(fibers, silentLogging, timeout(10.seconds))
final val genStringRedisTypeOption: Gen[Any, Option[RedisType]] =
Gen.option(Gen.constSample(Sample.noShrink(RedisType.String)))
......@@ -39,5 +36,5 @@ trait BaseSpec extends ZIOSpecDefault {
}
object BaseSpec {
final val ClusterExecutorUnsupported = "cluster executor unsupported"
final val ClusterExecutorUnsupported = "cluster executor not supported"
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册