...
 
Commits (6)
    https://gitcode.net/qq_34446485/zio-redis/-/commit/9268e9d446835e5bb89daea857989b387aea3f2d Support 'CLIENT INFO' and 'CLIENT LIST' commands (#807) 2023-04-09T13:19:00+02:00 Dragutin Marjanović dmarjanovic94@gmail.com https://gitcode.net/qq_34446485/zio-redis/-/commit/7b507fcb14f775b729575a34798d9bf22a0c3a55 Hide executors (#809) 2023-04-09T13:31:54+02:00 Dejan Mijić dmijic@acm.org https://gitcode.net/qq_34446485/zio-redis/-/commit/70d2b1015303deea284316a64dd7cf4e62567c91 Update README.md (#810) 2023-04-09T13:39:57+02:00 github-actions[bot] 41898282+github-actions[bot]@users.noreply.github.com Co-authored-by: <span data-trailer="Co-authored-by:"><a href="mailto:github-actions%5Bbot%5D@users.noreply.github.com" title="github-actions[bot]@users.noreply.github.com"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg6" style="text-decoration: none">N</a><a href="mailto:github-actions%5Bbot%5D@users.noreply.github.com" title="github-actions[bot]@users.noreply.github.com">github-actions[bot]</a> &lt;<a href="mailto:github-actions%5Bbot%5D@users.noreply.github.com" title="github-actions[bot]@users.noreply.github.com">github-actions[bot]@users.noreply.github.com</a>&gt;</span> https://gitcode.net/qq_34446485/zio-redis/-/commit/edbf01294614d9c9c570441eedfa2e0dadc917cc Remove redundant benchmarks (#811) 2023-04-09T21:25:15+02:00 Dejan Mijić dmijic@acm.org https://gitcode.net/qq_34446485/zio-redis/-/commit/b457e8ea6f80b147d471491222aa2beafd17fe2c Inline benchmark package object (#814) 2023-04-10T09:25:14+02:00 Dejan Mijić dmijic@acm.org https://gitcode.net/qq_34446485/zio-redis/-/commit/7dabd5b5b749d9558f95406fc1cc44e297dec181 Change return type of CLIENT INFO and CLIENT LIST (#813) 2023-04-10T20:42:49+02:00 Dragutin Marjanović dmarjanovic94@gmail.com * Remove unused class * Parse responses to ClientInfo * Improve docs * Address code remarks * Add 'from(char)' method to ClientFlag object * Add 'final' modifier * Make parsing ClientInfo safe * Use scala-collection-compat * Format code
......@@ -49,21 +49,19 @@ object ZIORedisExample extends ZIOAppDefault {
def get[A: Schema]: BinaryCodec[A] = ProtobufCodec.protobufCodec
}
val myApp: ZIO[Redis, RedisError, Unit] = for {
redis <- ZIO.service[Redis]
_ <- redis.set("myKey", 8L, Some(1.minutes))
v <- redis.get("myKey").returning[Long]
_ <- Console.printLine(s"Value of myKey: $v").orDie
_ <- redis.hSet("myHash", ("k1", 6), ("k2", 2))
_ <- redis.rPush("myList", 1, 2, 3, 4)
_ <- redis.sAdd("mySet", "a", "b", "a", "c")
} yield ()
override def run = myApp.provide(
Redis.layer,
SingleNodeExecutor.local,
ZLayer.succeed[CodecSupplier](ProtobufCodecSupplier)
)
val myApp: ZIO[Redis, RedisError, Unit] =
for {
redis <- ZIO.service[Redis]
_ <- redis.set("myKey", 8L, Some(1.minutes))
v <- redis.get("myKey").returning[Long]
_ <- Console.printLine(s"Value of myKey: $v").orDie
_ <- redis.hSet("myHash", ("k1", 6), ("k2", 2))
_ <- redis.rPush("myList", 1, 2, 3, 4)
_ <- redis.sAdd("mySet", "a", "b", "a", "c")
} yield ()
override def run =
myApp.provide(Redis.local, ZLayer.succeed[CodecSupplier](ProtobufCodecSupplier))
}
```
......@@ -108,9 +106,8 @@ object EmbeddedRedisSpec extends ZIOSpecDefault {
}
).provideShared(
EmbeddedRedis.layer,
SingleNodeExecutor.layer,
ZLayer.succeed[CodecSupplier](ProtobufCodecSupplier),
Redis.layer
Redis.singleNode
) @@ TestAspect.silentLogging
}
```
......
......@@ -45,7 +45,6 @@ lazy val redis =
.settings(
libraryDependencies ++= List(
"dev.zio" %% "zio-streams" % zioVersion,
"dev.zio" %% "zio-logging" % "2.1.11",
"dev.zio" %% "zio-schema" % zioSchemaVersion,
"dev.zio" %% "zio-schema-protobuf" % zioSchemaVersion % Test,
"dev.zio" %% "zio-test" % zioVersion % Test,
......@@ -85,10 +84,9 @@ lazy val benchmarks =
crossScalaVersions -= Scala3,
publish / skip := true,
libraryDependencies ++= List(
"dev.profunktor" %% "redis4cats-effects" % "1.4.1",
"io.chrisdavenport" %% "rediculous" % "0.4.0",
"io.laserdisc" %% "laserdisc-fs2" % "0.6.0",
"dev.zio" %% "zio-schema-protobuf" % zioSchemaVersion
"dev.profunktor" %% "redis4cats-effects" % "1.4.1",
"dev.zio" %% "zio-schema-protobuf" % zioSchemaVersion,
"org.typelevel" %% "cats-effect" % "3.4.8"
)
)
......
......@@ -49,21 +49,19 @@ object ZIORedisExample extends ZIOAppDefault {
def get[A: Schema]: BinaryCodec[A] = ProtobufCodec.protobufCodec
}
val myApp: ZIO[Redis, RedisError, Unit] = for {
redis <- ZIO.service[Redis]
_ <- redis.set("myKey", 8L, Some(1.minutes))
v <- redis.get("myKey").returning[Long]
_ <- Console.printLine(s"Value of myKey: $v").orDie
_ <- redis.hSet("myHash", ("k1", 6), ("k2", 2))
_ <- redis.rPush("myList", 1, 2, 3, 4)
_ <- redis.sAdd("mySet", "a", "b", "a", "c")
} yield ()
override def run = myApp.provide(
Redis.layer,
SingleNodeExecutor.local,
ZLayer.succeed[CodecSupplier](ProtobufCodecSupplier)
)
val myApp: ZIO[Redis, RedisError, Unit] =
for {
redis <- ZIO.service[Redis]
_ <- redis.set("myKey", 8L, Some(1.minutes))
v <- redis.get("myKey").returning[Long]
_ <- Console.printLine(s"Value of myKey: $v").orDie
_ <- redis.hSet("myHash", ("k1", 6), ("k2", 2))
_ <- redis.rPush("myList", 1, 2, 3, 4)
_ <- redis.sAdd("mySet", "a", "b", "a", "c")
} yield ()
override def run =
myApp.provide(Redis.local, ZLayer.succeed[CodecSupplier](ProtobufCodecSupplier))
}
```
......@@ -108,9 +106,8 @@ object EmbeddedRedisSpec extends ZIOSpecDefault {
}
).provideShared(
EmbeddedRedis.layer,
SingleNodeExecutor.layer,
ZLayer.succeed[CodecSupplier](ProtobufCodecSupplier),
Redis.layer
Redis.singleNode
) @@ TestAspect.silentLogging
}
```
......
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks
import cats.effect.unsafe.implicits.global
import cats.effect.{IO => CIO, Resource}
import com.comcast.ip4s._
import dev.profunktor.redis4cats.codecs.Codecs
import dev.profunktor.redis4cats.codecs.splits._
import dev.profunktor.redis4cats.data.RedisCodec
import dev.profunktor.redis4cats.effect.Log.NoOp.instance
import dev.profunktor.redis4cats.{Redis, RedisCommands}
import io.chrisdavenport.rediculous.RedisConnection
import io.lettuce.core.ClientOptions
import laserdisc.auto.autoRefine
import laserdisc.fs2.RedisClient
trait QueryRunner[Client] {
def unsafeRunWith(query: Client => CIO[Unit]): Unit
}
object QueryRunner {
def apply[Client](implicit instance: QueryRunner[Client]): QueryRunner[Client] = instance
implicit val laserDiscClientRunner: QueryRunner[LaserDiscClient] =
new QueryRunner[LaserDiscClient] {
def unsafeRunWith(f: LaserDiscClient => CIO[Unit]): Unit =
Laserdisc.use(f).unsafeRunSync()
}
implicit val rediculousRunner: QueryRunner[RediculousClient] =
new QueryRunner[RediculousClient] {
def unsafeRunWith(f: RediculousClient => CIO[Unit]): Unit =
Rediculous.use(f).unsafeRunSync()
}
implicit val redis4CatsStringRunner: QueryRunner[Redis4CatsClient[String]] =
new QueryRunner[Redis4CatsClient[String]] {
def unsafeRunWith(f: Redis4CatsClient[String] => CIO[Unit]): Unit =
Redis4CatsString.use(f).unsafeRunSync()
}
implicit val redis4CatsLongRunner: QueryRunner[Redis4CatsClient[Long]] =
new QueryRunner[Redis4CatsClient[Long]] {
def unsafeRunWith(f: Redis4CatsClient[Long] => CIO[Unit]): Unit =
Redis4CatsLong.use(f).unsafeRunSync()
}
private[this] final val RedisHost = "127.0.0.1"
private[this] final val RedisPort = 6379
private[this] final val Laserdisc: Resource[CIO, LaserDiscClient] = RedisClient[CIO].to(RedisHost, RedisPort)
private[this] final val Rediculous: Resource[CIO, RediculousClient] =
RedisConnection
.queued[CIO]
.withHost(host"127.0.0.1")
.withPort(port"6379")
.withMaxQueued(10000)
.withWorkers(2)
.build
private[this] final val Redis4CatsLong: Resource[CIO, RedisCommands[CIO, String, Long]] = {
val longCodec = Codecs.derive(RedisCodec.Utf8, stringLongEpi)
Redis[CIO].withOptions(s"redis://$RedisHost:$RedisPort", ClientOptions.create(), longCodec)
}
private[this] final val Redis4CatsString: Resource[CIO, RedisCommands[CIO, String, String]] =
Redis[CIO].utf8(s"redis://$RedisHost:$RedisPort")
}
......@@ -14,43 +14,43 @@
* limitations under the License.
*/
package zio.redis.benchmarks.lists
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class LMoveBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
package zio.redis.benchmarks
import cats.effect._
import cats.effect.unsafe.IORuntime
import dev.profunktor.redis4cats.codecs.Codecs
import dev.profunktor.redis4cats.codecs.splits._
import dev.profunktor.redis4cats.data.RedisCodec
import dev.profunktor.redis4cats.effect.Log.NoOp.instance
import dev.profunktor.redis4cats.{Redis, RedisCommands}
import io.lettuce.core.ClientOptions
private[benchmarks] final class Redis4Cats private (
client: RedisCommands[IO, String, Long],
finalizer: IO[Unit]
)(implicit runtime: IORuntime) {
def run(program: RedisCommands[IO, String, Long] => IO[Unit]): Unit = program(client).unsafeRunSync()
def tearDown(): Unit = finalizer.unsafeRunSync()
}
private var items: List[String] = _
private[benchmarks] object Redis4Cats {
implicit val runtime: IORuntime = IORuntime.global
private val key = "test-list"
def unsafeMake(): Redis4Cats = {
val resource = Redis[IO].withOptions(RedisUri, ClientOptions.create(), LongCodec)
val (client, finalizer) = extractResource(resource).unsafeRunSync()
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(ZIO.serviceWithZIO[Redis](_.rPush(key, items.head, items.tail: _*).unit))
new Redis4Cats(client, finalizer)
}
@TearDown(Level.Trial)
def tearDown(): Unit =
execute(ZIO.serviceWithZIO[Redis](_.del(key).unit))
private def extractResource[A](resource: Resource[IO, A]): IO[(A, IO[Unit])] =
for {
da <- Deferred[IO, A]
f <- resource.use(da.complete(_) >> IO.never).start
a <- da.get
} yield a -> f.cancel
@Benchmark
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(_ =>
ZIO.serviceWithZIO[Redis](_.lMove(key, key, Side.Left, Side.Right).returning[String])
)
)
private final val LongCodec = Codecs.derive(RedisCodec.Utf8, stringLongEpi)
private final val RedisUri = "redis://127.0.0.1:6379"
}
......@@ -14,14 +14,11 @@
* limitations under the License.
*/
package zio.redis.benchmarks.strings
package zio.redis.benchmarks
import cats.instances.list._
import cats.syntax.foldable._
import io.chrisdavenport.rediculous.{RedisCommands, RedisIO}
import cats.syntax.parallel._
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
......@@ -32,35 +29,52 @@ import java.util.concurrent.TimeUnit
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class IncrBenchmarks extends BenchmarkRuntime {
class SetGetBenchmark {
import SetGetBenchmark._
@Param(Array("500"))
var count: Int = _
@Param(Array("20"))
var parallelism: Int = _
private var items: List[String] = _
@Param(Array("500"))
var repetitions: Int = _
@Setup(Level.Trial)
@Setup
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(ZIO.foreachDiscard(items)(i => ZIO.serviceWithZIO[Redis](_.set(i, i))))
redis4Cats = Redis4Cats.unsafeMake()
zioRedis = ZioRedis.unsafeMake()
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
execute[LaserDiscClient](c => items.traverse_(i => c.send(cmd.incr[Long](Key.unsafeFrom(i)))))
@TearDown
def tearDown(): Unit = {
redis4Cats.tearDown()
zioRedis.tearDown()
}
@Benchmark
def rediculous(): Unit =
execute[RediculousClient](c => items.traverse_(i => RedisCommands.append[RedisIO](i, i).run(c)))
@Benchmark
def redis4cats(): Unit =
execute[Redis4CatsClient[Long]](c => items.traverse_(i => c.incr(i)))
redis4Cats.run { client =>
val task = client.set(TestKey, TestValue) >> client.get(TestKey)
val tasks = List.fill(parallelism)(task.replicateA_(repetitions))
tasks.parSequence_
}
@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(i => ZIO.serviceWithZIO[Redis](_.incr(i))))
def zio(): Unit =
zioRedis.run {
for {
redis <- ZIO.service[Redis]
task = redis.set(TestKey, TestValue) *> redis.get(TestKey).returning[Long]
tasks = Chunk.fill(parallelism)(task.repeatN(repetitions))
_ <- ZIO.collectAllParDiscard(tasks)
} yield ()
}
private var redis4Cats: Redis4Cats = _
private var zioRedis: ZioRedis = _
}
object SetGetBenchmark {
private final val TestKey = "TestKey"
private final val TestValue = 1024L
}
......@@ -16,29 +16,29 @@
package zio.redis.benchmarks
import cats.effect.{IO => CIO}
import zio._
import zio.redis._
import zio.schema.Schema
import zio.schema._
import zio.schema.codec.{BinaryCodec, ProtobufCodec}
trait BenchmarkRuntime {
final def execute(query: ZIO[Redis, RedisError, Unit]): Unit =
Unsafe.unsafe { implicit unsafe =>
Runtime.default.unsafe.run(query.provideLayer(BenchmarkRuntime.Layer)).getOrThrowFiberFailure()
}
private[benchmarks] final class ZioRedis private (runtime: Runtime.Scoped[Redis]) {
def run(program: ZIO[Redis, RedisError, Unit]): Unit =
Unsafe.unsafe(implicit u => runtime.unsafe.run(program).getOrThrow())
final def execute[Client: QueryRunner](query: Client => CIO[Unit]): Unit =
QueryRunner[Client].unsafeRunWith(query)
def tearDown(): Unit =
Unsafe.unsafe(implicit u => runtime.unsafe.shutdown())
}
object BenchmarkRuntime {
private final val Layer =
ZLayer.make[Redis](
SingleNodeExecutor.local,
ZLayer.succeed[CodecSupplier](new CodecSupplier {
def get[A: Schema]: BinaryCodec[A] = ProtobufCodec.protobufCodec
}),
Redis.layer
)
private[benchmarks] object ZioRedis {
def unsafeMake(): ZioRedis = {
val runtime = Unsafe.unsafe(implicit u => Runtime.unsafe.fromLayer(TestLayer))
new ZioRedis(runtime)
}
private object ProtobufCodecSupplier extends CodecSupplier {
def get[A: Schema]: BinaryCodec[A] = ProtobufCodec.protobufCodec
}
private final val TestLayer =
ZLayer.make[Redis](Redis.local, ZLayer.succeed(ProtobufCodecSupplier))
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.hash
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class HDelBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var size: Int = _
private var items: List[(String, String)] = _
private val key = "test-hash"
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to size).map(e => e.toString -> e.toString).toList
execute(ZIO.serviceWithZIO[Redis](_.hSet(key, items.head, items.tail: _*).unit))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.implicits.toFoldableOps
import cats.instances.list._
execute[LaserDiscClient](c => items.traverse_(it => c.send(cmd.hdel(Key.unsafeFrom(key), Key.unsafeFrom(it._1)))))
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(it => RedisCommands.hdel[RedisIO](key, List(it._1)).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(it => c.hDel(key, it._1)))
}
@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(it => ZIO.serviceWithZIO[Redis](_.hDel(key, it._1))))
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.hash
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class HExistsBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var size: Int = _
private var items: List[(String, String)] = _
private val key = "test-hash"
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to size).map(e => e.toString -> e.toString).toList
execute(ZIO.serviceWithZIO[Redis](_.hSet(key, items.head, items.tail: _*).unit))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.implicits.toFoldableOps
import cats.instances.list._
execute[LaserDiscClient](c =>
items.traverse_(it => c.send(cmd.hexists(Key.unsafeFrom(key), Key.unsafeFrom(it._1))))
)
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(it => RedisCommands.hexists[RedisIO](key, it._1).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(it => c.hExists(key, it._1)))
}
@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(it => ZIO.serviceWithZIO[Redis](_.hExists(key, it._1))))
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.hash
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class HGetAllBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var size: Int = _
private var items: List[(String, String)] = _
private val key = "test-hash"
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to size).map(e => e.toString -> e.toString).toList
execute(ZIO.serviceWithZIO[Redis](_.hSet(key, items.head, items.tail: _*).unit))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.implicits.toFoldableOps
import cats.instances.list._
execute[LaserDiscClient](c => items.traverse_(_ => c.send(cmd.hgetall(Key.unsafeFrom(key)))))
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(_ => RedisCommands.hgetall[RedisIO](key).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(_ => c.hGetAll(key)))
}
@Benchmark
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(_ => ZIO.serviceWithZIO[Redis](_.hGetAll(key).returning[String, String]))
)
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.hash
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class HGetBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var size: Int = _
private var items: List[(String, String)] = _
private val key = "test-hash"
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to size).map(e => e.toString -> e.toString).toList
execute(ZIO.serviceWithZIO[Redis](_.hSet(key, items.head, items.tail: _*).unit))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.implicits.toFoldableOps
import cats.instances.list._
execute[LaserDiscClient](c =>
items.traverse_(it => c.send(cmd.hget[String](Key.unsafeFrom(key), Key.unsafeFrom(it._1))))
)
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(it => RedisCommands.hget[RedisIO](key, it._1).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(it => c.hGet(key, it._1)))
}
@Benchmark
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(it => ZIO.serviceWithZIO[Redis](_.hGet(key, it._1).returning[String]))
)
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.hash
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class HIncrbyBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var size: Int = _
@Param(Array("1"))
var increment: Long = _
private var items: List[(String, String)] = _
private val key = "test-hash"
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to size).map(e => e.toString -> e.toString).toList
execute(ZIO.serviceWithZIO[Redis](_.hSet(key, items.head, items.tail: _*).unit))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import cats.implicits.toFoldableOps
import _root_.laserdisc.{all => cmd, _}
import cats.instances.list._
execute[LaserDiscClient](c =>
items.traverse_(it =>
c.send(cmd.hincrby(Key.unsafeFrom(key), Key.unsafeFrom(it._1), NonZeroLong.unsafeFrom(increment)))
)
)
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(it => RedisCommands.hincrby[RedisIO](key, it._1, increment).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.syntax.foldable._
execute[Redis4CatsClient[Long]](c => items.traverse_(it => c.hIncrBy(key, it._1, increment)))
}
@Benchmark
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(it => ZIO.serviceWithZIO[Redis](_.hIncrBy(key, it._1, increment)))
)
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.hash
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class HIncrbyFloatBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var size: Int = _
@Param(Array("1.0"))
var increment: Double = _
private var items: List[(String, String)] = _
private val key = "test-hash"
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to size).map(e => e.toString -> e.toString).toList
execute(ZIO.serviceWithZIO[Redis](_.hSet(key, items.head, items.tail: _*).unit))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.implicits.toFoldableOps
import cats.instances.list._
execute[LaserDiscClient](c =>
items.traverse_(it =>
c.send(cmd.hincrby(Key.unsafeFrom(key), Key.unsafeFrom(it._1), NonZeroDouble.unsafeFrom(increment)))
)
)
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c =>
items.traverse_(it => RedisCommands.hincrbyfloat[RedisIO](key, it._1, increment).run(c))
)
}
@Benchmark
def redis4cats(): Unit = {
import cats.syntax.foldable._
execute[Redis4CatsClient[Long]](c => items.traverse_(it => c.hIncrByFloat(key, it._1, increment)))
}
@Benchmark
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(it => ZIO.serviceWithZIO[Redis](_.hIncrByFloat(key, it._1, increment)))
)
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.hash
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class HKeysBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var size: Int = _
private var items: List[(String, String)] = _
private val key = "test-hash"
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to size).map(e => e.toString -> e.toString).toList
execute(ZIO.serviceWithZIO[Redis](_.hSet(key, items.head, items.tail: _*).unit))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.implicits.toFoldableOps
import cats.instances.list._
execute[LaserDiscClient](c => items.traverse_(_ => c.send(cmd.hkeys(Key.unsafeFrom(key)))))
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(_ => RedisCommands.hkeys[RedisIO](key).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(_ => c.hKeys(key)))
}
@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(_ => ZIO.serviceWithZIO[Redis](_.hKeys(key).returning[String])))
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.hash
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class HLenBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var size: Int = _
private var items: List[(String, String)] = _
private val key = "test-hash"
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to size).map(e => e.toString -> e.toString).toList
execute(ZIO.serviceWithZIO[Redis](_.hSet(key, items.head, items.tail: _*).unit))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.implicits.toFoldableOps
import cats.instances.list._
execute[LaserDiscClient](c => items.traverse_(_ => c.send(cmd.hlen(Key.unsafeFrom(key)))))
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(_ => RedisCommands.hlen[RedisIO](key).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(_ => c.hLen(key)))
}
@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(_ => ZIO.serviceWithZIO[Redis](_.hLen(key))))
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.hash
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class HMGetBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var size: Int = _
private var items: List[(String, String)] = _
private val key = "test-hash"
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to size).map(e => e.toString -> e.toString).toList
execute(ZIO.serviceWithZIO[Redis](_.hSet(key, items.head, items.tail: _*).unit))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.implicits.toFoldableOps
import cats.instances.list._
execute[LaserDiscClient](c =>
items.traverse_(it => c.send(cmd.hmget[String](Key.unsafeFrom(key), Key.unsafeFrom(it._1))))
)
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(it => RedisCommands.hmget[RedisIO](key, List(it._1)).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(it => c.hmGet(key, it._1)))
}
@Benchmark
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(it => ZIO.serviceWithZIO[Redis](_.hmGet(key, it._1).returning[String]))
)
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.hash
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class HMSetBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var size: Int = _
private var items: List[(String, String)] = _
private val key = "test-hash"
@Setup(Level.Trial)
def setup(): Unit =
items = (0 to size).map(e => e.toString -> e.toString).toList
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.implicits.toFoldableOps
import cats.instances.list._
execute[LaserDiscClient](c =>
items.traverse_(it => c.send(cmd.hmset[String](Key.unsafeFrom(key), Key.unsafeFrom(it._1), it._2)))
)
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(it => RedisCommands.hmset[RedisIO](key, List(it)).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(it => c.hmSet(key, Map(it._1 -> it._2)): @annotation.nowarn))
}
@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(it => ZIO.serviceWithZIO[Redis](_.hmSet(key, it))))
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.hash
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class HSetBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var size: Int = _
private var items: List[(String, String)] = _
private val key = "test-hash"
@Setup(Level.Trial)
def setup(): Unit =
items = (0 to size).map(e => e.toString -> e.toString).toList
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.implicits.toFoldableOps
import cats.instances.list._
execute[LaserDiscClient](c =>
items.traverse_(it => c.send(cmd.hset[String](Key.unsafeFrom(key), Key.unsafeFrom(it._1), it._2)))
)
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(it => RedisCommands.hset[RedisIO](key, it._1, it._2).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(it => c.hSet(key, it._1, it._2)))
}
@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(it => ZIO.serviceWithZIO[Redis](_.hSet(key, it))))
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.hash
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class HSetNxBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var size: Int = _
private var items: List[(String, String)] = _
private val key = "test-hash"
@Setup(Level.Trial)
def setup(): Unit =
items = (0 to size).map(e => e.toString -> e.toString).toList
// zioUnsafeRun(hSet(key, items.head, items.tail: _*).unit)
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.implicits.toFoldableOps
import cats.instances.list._
execute[LaserDiscClient](c =>
items.traverse_(it => c.send(cmd.hsetnx[String](Key.unsafeFrom(key), Key.unsafeFrom(it._1), it._2)))
)
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(it => RedisCommands.hsetnx[RedisIO](key, it._1, it._2).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(it => c.hSetNx(key, it._1, it._2)))
}
@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(it => ZIO.serviceWithZIO[Redis](_.hSetNx(key, it._1, it._2))))
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.hash
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class HStrLenBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var size: Int = _
private var items: List[(String, String)] = _
private val key = "test-hash"
def setup(): Unit = {
items = (0 to size).map(e => e.toString -> e.toString).toList
execute(ZIO.serviceWithZIO[Redis](_.hSet(key, items.head, items.tail: _*).unit))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.implicits.toFoldableOps
import cats.instances.list._
execute[LaserDiscClient](c =>
items.traverse_(it => c.send(cmd.hstrlen(Key.unsafeFrom(key), Key.unsafeFrom(it._1))))
)
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(it => RedisCommands.hstrlen[RedisIO](key, it._1).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(it => c.hStrLen(key, it._1)))
}
@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(it => ZIO.serviceWithZIO[Redis](_.hStrLen(key, it._1))))
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.hash
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class HValsBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var size: Int = _
private var items: List[(String, String)] = _
private val key = "test-hash"
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to size).map(e => e.toString -> e.toString).toList
execute(ZIO.serviceWithZIO[Redis](_.hSet(key, items.head, items.tail: _*).unit))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.implicits.toFoldableOps
import cats.instances.list._
execute[LaserDiscClient](c => items.traverse_(_ => c.send(cmd.hvals(Key.unsafeFrom(key)))))
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(_ => RedisCommands.hvals[RedisIO](key).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(_ => c.hVals(key)))
}
@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(_ => ZIO.serviceWithZIO[Redis](_.hVals(key).returning[String])))
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.lists
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class BlMoveBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
private val key = "test-list"
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(ZIO.serviceWithZIO[Redis](_.rPush(key, items.head, items.tail: _*).unit))
}
@TearDown(Level.Trial)
def tearDown(): Unit =
execute(ZIO.serviceWithZIO[Redis](_.del(key).unit))
@Benchmark
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(_ =>
ZIO.serviceWithZIO[Redis](_.blMove(key, key, Side.Left, Side.Right, 1.second).returning[String])
)
)
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.lists
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class BlPopBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
private val key = "test-list"
@Setup(Level.Invocation)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(ZIO.serviceWithZIO[Redis](_.rPush(key, items.head, items.tail: _*).unit))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c =>
items.traverse_(_ => c.send(cmd.blocking.blpop[String](Key.unsafeFrom(key), PosInt.unsafeFrom(1))))
)
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(_ => RedisCommands.blpop[RedisIO](List(key), 1).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.data._
import cats.instances.list._
import cats.syntax.foldable._
import scala.concurrent.duration._
execute[Redis4CatsClient[String]](c =>
items.traverse_(_ => c.blPop(Duration(1, TimeUnit.SECONDS), NonEmptyList.one(key)))
)
}
@Benchmark
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(_ => ZIO.serviceWithZIO[Redis](_.blPop(key)(1.second).returning[String]))
)
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.lists
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class BrPopBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
private val key = "test-list"
@Setup(Level.Invocation)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(ZIO.serviceWithZIO[Redis](_.rPush(key, items.head, items.tail: _*).unit))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c =>
items.traverse_(_ => c.send(cmd.blocking.brpop[String](Key.unsafeFrom(key), PosInt.unsafeFrom(1))))
)
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(_ => RedisCommands.brpop[RedisIO](List(key), 1).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.data._
import cats.instances.list._
import cats.syntax.foldable._
import scala.concurrent.duration._
execute[Redis4CatsClient[String]](c =>
items.traverse_(_ => c.brPop(Duration(1, TimeUnit.SECONDS), NonEmptyList.one(key)))
)
}
@Benchmark
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(_ => ZIO.serviceWithZIO[Redis](_.brPop(key)(1.second).returning[String]))
)
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.lists
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class BrPopLPushBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
private val key = "test-list"
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(ZIO.serviceWithZIO[Redis](_.rPush(key, items.head, items.tail: _*).unit))
}
@TearDown(Level.Trial)
def tearDown(): Unit =
execute(ZIO.serviceWithZIO[Redis](_.del(key).unit))
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c =>
items.traverse_(_ =>
c.send(
cmd.blocking.brpoplpush[String](Key.unsafeFrom(key), Key.unsafeFrom(key), PosInt.unsafeFrom(1))
)
)
)
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(_ => RedisCommands.brpoplpush[RedisIO](key, key, 1).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
import scala.concurrent.duration._
execute[Redis4CatsClient[String]](c => items.traverse_(_ => c.brPopLPush(Duration(1, TimeUnit.SECONDS), key, key)))
}
@Benchmark
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(_ => ZIO.serviceWithZIO[Redis](_.brPopLPush(key, key, 1.second).returning[String]))
)
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.lists
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class LIndexBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[Int] = _
private val key = "test-list"
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to count).toList
execute(ZIO.serviceWithZIO[Redis](_.rPush(key, items.head, items.tail: _*).unit))
}
@TearDown(Level.Trial)
def tearDown(): Unit =
execute(ZIO.serviceWithZIO[Redis](_.del(key).unit))
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c =>
items.traverse_(i => c.send(cmd.lindex[String](Key.unsafeFrom(key), Index.unsafeFrom(i.toLong))))
)
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(i => RedisCommands.lindex[RedisIO](key, i).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(i => c.lIndex(key, i.toLong)))
}
@Benchmark
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(i => ZIO.serviceWithZIO[Redis](_.lIndex(key, i.toLong).returning[String]))
)
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.lists
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class LInsertBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
private val key = "test-list"
@Setup(Level.Invocation)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(ZIO.serviceWithZIO[Redis](_.rPush(key, items.head, items.tail: _*).unit))
}
@TearDown(Level.Invocation)
def tearDown(): Unit =
execute(ZIO.serviceWithZIO[Redis](_.del(key).unit))
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import _root_.laserdisc.lists.listtypes._
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c =>
items.traverse_(i => c.send(cmd.linsert[String](Key.unsafeFrom(key), ListPosition.before, i, i)))
)
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(i => RedisCommands.linsertbefore[RedisIO](key, i, i).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(i => c.lInsertBefore(key, i, i)))
}
@Benchmark
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(i => ZIO.serviceWithZIO[Redis](_.lInsert[String, String](key, Position.Before, i, i)))
)
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.lists
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class LLenBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
private val key = "test-list"
@Setup(Level.Trial)
def setup(): Unit =
items = (0 to count).toList.map(_.toString)
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c => items.traverse_(_ => c.send(cmd.llen(Key.unsafeFrom(key)))))
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(_ => RedisCommands.llen[RedisIO](key).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(_ => c.lLen(key)))
}
@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(_ => ZIO.serviceWithZIO[Redis](_.lLen[String](key))))
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.lists
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class LPopBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
private val key = "test-list"
@Setup(Level.Invocation)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(ZIO.serviceWithZIO[Redis](_.rPush(key, items.head, items.tail: _*).unit))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c => items.traverse_(_ => c.send(cmd.lpop[String](Key.unsafeFrom(key)))))
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(_ => RedisCommands.lpop[RedisIO](key).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(_ => c.lPop(key)))
}
@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(_ => ZIO.serviceWithZIO[Redis](_.lPop(key).returning[String])))
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.lists
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class LPosCountBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
private val key = "test-list"
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(ZIO.serviceWithZIO[Redis](_.rPush(key, items.head, items.tail: _*).unit))
}
@TearDown(Level.Trial)
def tearDown(): Unit =
execute(ZIO.serviceWithZIO[Redis](_.del(key).unit))
@Benchmark
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(i => ZIO.serviceWithZIO[Redis](_.lPosCount[String, String](key, i, Count(0L))))
)
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.lists
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class LPushBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
private val key = "test-list"
@Setup(Level.Trial)
def setup(): Unit =
items = (0 to count).toList.map(_.toString)
@TearDown(Level.Invocation)
def tearDown(): Unit =
execute(ZIO.serviceWithZIO[Redis](_.del(key).unit))
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c => items.traverse_(i => c.send(cmd.lpush[String](Key.unsafeFrom(key), i))))
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(i => RedisCommands.lpush[RedisIO](key, List(i)).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(i => c.lPush(key, i)))
}
@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(i => ZIO.serviceWithZIO[Redis](_.lPush[String, String](key, i))))
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.lists
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class LPushXBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
private val key = "test-list"
@Setup(Level.Invocation)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(ZIO.serviceWithZIO[Redis](_.rPush(key, items.head).unit))
}
@TearDown(Level.Invocation)
def tearDown(): Unit =
execute(ZIO.serviceWithZIO[Redis](_.del(key).unit))
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c => items.traverse_(i => c.send(cmd.lpushx[String](Key.unsafeFrom(key), i))))
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(i => RedisCommands.lpushx[RedisIO](key, i).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(i => c.lPushX(key, i)))
}
@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(i => ZIO.serviceWithZIO[Redis](_.lPushX[String, String](key, i))))
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.lists
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class LRangeBenchmarks extends BenchmarkRuntime {
@Param(Array("400"))
var count: Int = _
private var items: List[Int] = _
private val key = "test-list"
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to count).toList
execute(ZIO.serviceWithZIO[Redis](_.rPush(key, items.head, items.tail: _*).unit))
}
@TearDown(Level.Trial)
def tearDown(): Unit =
execute(ZIO.serviceWithZIO[Redis](_.del(key).unit))
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c =>
items.traverse_(i => c.send(cmd.lrange[String](Key.unsafeFrom(key), Index(0L), Index.unsafeFrom(i.toLong))))
)
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(i => RedisCommands.lrange[RedisIO](key, 0L, i.toLong).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(i => c.lRange(key, 0L, i.toLong)))
}
@Benchmark
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(i => ZIO.serviceWithZIO[Redis](_.lRange(key, 0 to i).returning[String]))
)
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.lists
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class LRemBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
private val key = "test-list"
@Setup(Level.Invocation)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(ZIO.serviceWithZIO[Redis](_.rPush(key, items.head, items.tail: _*).unit))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c => items.traverse_(i => c.send(cmd.lrem[String](Key.unsafeFrom(key), Index(0), i))))
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(i => RedisCommands.lrem[RedisIO](key, 0, i).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(i => c.lRem(key, 0, i)))
}
@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(i => ZIO.serviceWithZIO[Redis](_.lRem[String](key, 0, i))))
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.lists
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class LSetBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[Long] = _
private val key = "test-list"
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to count).toList.map(_.toLong)
execute(ZIO.serviceWithZIO[Redis](_.rPush(key, items.head, items.tail: _*).unit))
}
@TearDown(Level.Trial)
def tearDown(): Unit =
execute(ZIO.serviceWithZIO[Redis](_.del(key).unit))
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c =>
items.traverse_(i => c.send(cmd.lset[String](Key.unsafeFrom(key), Index.unsafeFrom(i), i.toString)))
)
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(i => RedisCommands.lset[RedisIO](key, i, i.toString).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(i => c.lSet(key, i, i.toString)))
}
@Benchmark
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(i => ZIO.serviceWithZIO[Redis](_.lSet[String, String](key, i, i.toString)))
)
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.lists
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class LTrimBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[Int] = _
private val key = "test-list"
@Setup(Level.Invocation)
def setup(): Unit = {
items = (count to 0 by -1).toList
execute(ZIO.serviceWithZIO[Redis](_.rPush(key, items.head, items.tail: _*).unit))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c =>
items.traverse_(i => c.send(cmd.ltrim(Key.unsafeFrom(key), Index(1L), Index.unsafeFrom(i.toLong))))
)
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(i => RedisCommands.ltrim[RedisIO](key, 1L, i.toLong).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(i => c.lTrim(key, 1L, i.toLong)))
}
@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(i => ZIO.serviceWithZIO[Redis](_.lTrim[String](key, 1 to i))))
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.lists
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class RPopBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
private val key = "test-list"
@Setup(Level.Invocation)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(ZIO.serviceWithZIO[Redis](_.rPush(key, items.head, items.tail: _*).unit))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c => items.traverse_(_ => c.send(cmd.rpop[String](Key.unsafeFrom(key)))))
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(_ => RedisCommands.rpop[RedisIO](key).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(_ => c.rPop(key)))
}
@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(_ => ZIO.serviceWithZIO[Redis](_.rPop(key).returning[String])))
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.lists
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class RPopLPushBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
private val key = "test-list"
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(ZIO.serviceWithZIO[Redis](_.rPush(key, items.head, items.tail: _*).unit))
}
@TearDown(Level.Trial)
def tearDown(): Unit =
execute(ZIO.serviceWithZIO[Redis](_.del(key).unit))
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c =>
items.traverse_(_ => c.send(cmd.rpoplpush[String](Key.unsafeFrom(key), Key.unsafeFrom(key))))
)
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(_ => RedisCommands.rpoplpush[RedisIO](key, key).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(_ => c.rPopLPush(key, key)))
}
@Benchmark
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(_ => ZIO.serviceWithZIO[Redis](_.rPopLPush(key, key).returning[String]))
)
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.lists
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class RPushBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
private val key = "test-list"
@Setup(Level.Trial)
def setup(): Unit =
items = (0 to count).toList.map(_.toString)
@TearDown(Level.Invocation)
def tearDown(): Unit =
execute(ZIO.serviceWithZIO[Redis](_.del(key).unit))
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c => items.traverse_(i => c.send(cmd.rpush[String](Key.unsafeFrom(key), i))))
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(i => RedisCommands.rpush[RedisIO](key, List(i)).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(i => c.rPush(key, i)))
}
@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(i => ZIO.serviceWithZIO[Redis](_.rPush[String, String](key, i))))
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.lists
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class RPushXBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
private val key = "test-list"
@Setup(Level.Invocation)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(ZIO.serviceWithZIO[Redis](_.rPush(key, items.head).unit))
}
@TearDown(Level.Invocation)
def tearDown(): Unit =
execute(ZIO.serviceWithZIO[Redis](_.del(key).unit))
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c => items.traverse_(i => c.send(cmd.rpushx[String](Key.unsafeFrom(key), i))))
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(i => RedisCommands.rpushx[RedisIO](key, i).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(i => c.rPushX(key, i)))
}
@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(i => ZIO.serviceWithZIO[Redis](_.rPushX[String, String](key, i))))
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.sets
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class SAddBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
private val key = "test-set"
@Setup(Level.Trial)
def setup(): Unit =
items = (0 to count).toList.map(_.toString)
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c => items.traverse_(i => c.send(cmd.sadd(Key.unsafeFrom(key), i))))
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(i => RedisCommands.sadd[RedisIO](key, List(i)).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(i => c.sAdd(key, i)))
}
@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(i => ZIO.serviceWithZIO[Redis](_.sAdd(key, i))))
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.sets
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class SCardBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
private val key = "test-set"
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(ZIO.serviceWithZIO[Redis](_.sAdd(key, items.head, items.tail: _*).unit))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c => items.traverse_(_ => c.send(cmd.scard(Key.unsafeFrom(key)))))
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(_ => RedisCommands.scard[RedisIO](key).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(_ => c.sCard(key)))
}
@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(_ => ZIO.serviceWithZIO[Redis](_.sCard(key))))
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.sets
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class SDiffBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
private var otherItems: List[String] = _
private val key = "test-set1"
private val otherKey = "test-set2"
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
otherItems = (0 to count).toList.map(_.toString)
execute(ZIO.serviceWithZIO[Redis](_.sAdd(key, items.head, items.tail: _*).unit))
execute(ZIO.serviceWithZIO[Redis](_.sAdd(otherKey, otherItems.head, otherItems.tail: _*).unit))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.{all => cmd, _}
import _root_.laserdisc.fs2._
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c =>
items.traverse_(_ => c.send(cmd.sdiff(Key.unsafeFrom(key), Key.unsafeFrom(otherKey))))
)
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(_ => RedisCommands.sdiff[RedisIO](List(key, otherKey)).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(_ => c.sDiff(key, otherKey)))
}
@Benchmark
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(_ => ZIO.serviceWithZIO[Redis](_.sDiff(key, otherKey).returning[String]))
)
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.sets
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class SDiffStoreBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
private var otherItems: List[String] = _
private val key = "test-set1"
private val otherKey = "test-set2"
private val destinationKey = "test-set3"
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
otherItems = (0 to count).toList.map(_.toString)
execute(ZIO.serviceWithZIO[Redis](_.sAdd(key, items.head, items.tail: _*).unit))
execute(ZIO.serviceWithZIO[Redis](_.sAdd(otherKey, otherItems.head, otherItems.tail: _*).unit))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c =>
items.traverse_(_ =>
c.send(cmd.sdiffstore(Key.unsafeFrom(key), Key.unsafeFrom(otherKey), Key.unsafeFrom(destinationKey)))
)
)
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c =>
items.traverse_(_ => RedisCommands.sdiffstore[RedisIO](destinationKey, List(key, otherKey)).run(c))
)
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(_ => c.sDiffStore(destinationKey, key, otherKey)))
}
@Benchmark
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(_ => ZIO.serviceWithZIO[Redis](_.sDiffStore(destinationKey, key, otherKey)))
)
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.sets
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class SInterBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
private var otherItems: List[String] = _
private val key = "test-set1"
private val otherKey = "test-set2"
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
otherItems = (0 to count).toList.map(_.toString)
execute(ZIO.serviceWithZIO[Redis](_.sAdd(key, items.head, items.tail: _*).unit))
execute(ZIO.serviceWithZIO[Redis](_.sAdd(otherKey, otherItems.head, otherItems.tail: _*).unit))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c =>
items.traverse_(_ => c.send(cmd.sinter(Key.unsafeFrom(key), Key.unsafeFrom(otherKey))))
)
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(_ => RedisCommands.sinter[RedisIO](List(key, otherKey)).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(_ => c.sInter(key, otherKey)))
}
@Benchmark
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(_ => ZIO.serviceWithZIO[Redis](_.sInter(key, otherKey).returning[String]))
)
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.sets
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class SInterStoreBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
private var otherItems: List[String] = _
private val key = "test-set1"
private val otherKey = "test-set2"
private val destinationKey = "test-set3"
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
otherItems = (0 to count).toList.map(_.toString)
execute(ZIO.serviceWithZIO[Redis](_.sAdd(key, items.head, items.tail: _*).unit))
execute(ZIO.serviceWithZIO[Redis](_.sAdd(otherKey, otherItems.head, otherItems.tail: _*).unit))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c =>
items.traverse_(_ =>
c.send(cmd.sinterstore(Key.unsafeFrom(key), Key.unsafeFrom(otherKey), Key.unsafeFrom(destinationKey)))
)
)
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c =>
items.traverse_(_ => RedisCommands.sinterstore[RedisIO](destinationKey, List(key, otherKey)).run(c))
)
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(_ => c.sInterStore(destinationKey, key, otherKey)))
}
@Benchmark
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(_ => ZIO.serviceWithZIO[Redis](_.sInterStore(destinationKey, key, otherKey)))
)
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.sets
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class SIsMemberBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
private val key = "test-set1"
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(ZIO.serviceWithZIO[Redis](_.sAdd(key, items.head, items.tail: _*).unit))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c => items.traverse_(i => c.send(cmd.sismember(Key.unsafeFrom(key), i))))
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(i => RedisCommands.sismember[RedisIO](key, i).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(i => c.sIsMember(key, i)))
}
@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(i => ZIO.serviceWithZIO[Redis](_.sIsMember(key, i))))
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.sets
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class SMembersBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
private val key = "test-set"
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(ZIO.serviceWithZIO[Redis](_.sAdd(key, items.head, items.tail: _*).unit))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.{all => cmd, _}
import _root_.laserdisc.fs2._
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c => items.traverse_(_ => c.send(cmd.smembers(Key.unsafeFrom(key)))))
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(_ => RedisCommands.smembers[RedisIO](key).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(_ => c.sMembers(key)))
}
@Benchmark
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(_ => ZIO.serviceWithZIO[Redis](_.sMembers(key).returning[String]))
)
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.sets
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class SMoveBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
private val key = "test-set1"
private val destinationKey = "test-set2"
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(ZIO.serviceWithZIO[Redis](_.sAdd(key, items.head, items.tail: _*).unit))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c =>
items.traverse_(i => c.send(cmd.smove(Key.unsafeFrom(key), Key.unsafeFrom(destinationKey), Key.unsafeFrom(i))))
)
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(i => RedisCommands.smove[RedisIO](key, destinationKey, i).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(i => c.sMove(key, destinationKey, i)))
}
@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(i => ZIO.serviceWithZIO[Redis](_.sMove(key, destinationKey, i))))
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.sets
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class SPopBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
private val key = "test-set"
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(ZIO.serviceWithZIO[Redis](_.sAdd(key, items.head, items.tail: _*).unit))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c => items.traverse_(_ => c.send(cmd.spop(Key.unsafeFrom(key)))))
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(_ => RedisCommands.spop[RedisIO](key).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(_ => c.sPop(key)))
}
@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(_ => ZIO.serviceWithZIO[Redis](_.sPop(key).returning[String])))
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.sets
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class SRandMemberBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
private val key = "test-set"
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(ZIO.serviceWithZIO[Redis](_.sAdd(key, items.head, items.tail: _*).unit))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c => items.traverse_(_ => c.send(cmd.srandmember(Key.unsafeFrom(key)))))
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(_ => RedisCommands.srandmember[RedisIO](key).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(_ => c.sRandMember(key)))
}
@Benchmark
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(_ => ZIO.serviceWithZIO[Redis](_.sRandMember(key).returning[String]))
)
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.sets
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class SRemBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
private val key = "test-set"
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(ZIO.serviceWithZIO[Redis](_.sAdd(key, items.head, items.tail: _*).unit))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c => items.traverse_(i => c.send(cmd.srem(Key.unsafeFrom(key), i))))
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(i => RedisCommands.srem[RedisIO](key, List(i)).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(i => c.sRem(key, i)))
}
@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(i => ZIO.serviceWithZIO[Redis](_.sRem(key, i))))
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.sets
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class SUnionBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
private var otherItems: List[String] = _
private val key = "test-set1"
private val otherKey = "test-set2"
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
otherItems = (0 to count).toList.map(_.toString)
execute(ZIO.serviceWithZIO[Redis](_.sAdd(key, items.head, items.tail: _*).unit))
execute(ZIO.serviceWithZIO[Redis](_.sAdd(otherKey, otherItems.head, otherItems.tail: _*).unit))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c =>
items.traverse_(_ => c.send(cmd.sunion(Key.unsafeFrom(key), Key.unsafeFrom(otherKey))))
)
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(_ => RedisCommands.sunion[RedisIO](List(key, otherKey)).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(_ => c.sUnion(key, otherKey)))
}
@Benchmark
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(_ => ZIO.serviceWithZIO[Redis](_.sUnion(key, otherKey).returning[String]))
)
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.sets
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class SUnionStoreBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
private var otherItems: List[String] = _
private val key = "test-set1"
private val otherKey = "test-set2"
private val destinationKey = "test-set3"
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
otherItems = (0 to count).toList.map(_.toString)
execute(ZIO.serviceWithZIO[Redis](_.sAdd(key, items.head, items.tail: _*).unit))
execute(ZIO.serviceWithZIO[Redis](_.sAdd(otherKey, otherItems.head, otherItems.tail: _*).unit))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c =>
items.traverse_(_ =>
c.send(cmd.sunionstore(Key.unsafeFrom(key), Key.unsafeFrom(key), Key.unsafeFrom(destinationKey)))
)
)
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c =>
items.traverse_(_ => RedisCommands.sunionstore[RedisIO](destinationKey, List(key, otherKey)).run(c))
)
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(_ => c.sUnionStore(destinationKey, key, otherKey)))
}
@Benchmark
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(_ => ZIO.serviceWithZIO[Redis](_.sUnionStore(destinationKey, key, otherKey)))
)
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.strings
import cats.instances.list._
import cats.syntax.foldable._
import io.chrisdavenport.rediculous.{RedisCommands, RedisIO}
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class AppendBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(ZIO.foreachDiscard(items)(i => ZIO.serviceWithZIO[Redis](_.set(i, i))))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
execute[LaserDiscClient](c => items.traverse_(i => c.send(cmd.append(Key.unsafeFrom(i), i))))
}
@Benchmark
def rediculous(): Unit =
execute[RediculousClient](c => items.traverse_(i => RedisCommands.append[RedisIO](i, i).run(c)))
@Benchmark
def redis4cats(): Unit =
execute[Redis4CatsClient[String]](c => items.traverse_(i => c.append(i, i)))
@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(i => ZIO.serviceWithZIO[Redis](_.append(i, i))))
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.strings
import cats.instances.list._
import cats.syntax.foldable._
import io.chrisdavenport.rediculous.{RedisCommands, RedisIO}
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class DecrBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(ZIO.foreachDiscard(items)(i => ZIO.serviceWithZIO[Redis](_.set(i, i))))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
execute[LaserDiscClient](c => items.traverse_(i => c.send(cmd.decr[Long](Key.unsafeFrom(i)))))
}
@Benchmark
def rediculous(): Unit =
execute[RediculousClient](c => items.traverse_(i => RedisCommands.decr[RedisIO](i).run(c)))
@Benchmark
def redis4cats(): Unit =
execute[Redis4CatsClient[Long]](c => items.traverse_(i => c.decr(i)))
@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(i => ZIO.serviceWithZIO[Redis](_.decr(i))))
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.strings
import cats.instances.list._
import cats.syntax.foldable._
import io.chrisdavenport.rediculous.{RedisCommands, RedisIO}
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class GetBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(ZIO.foreachDiscard(items)(i => ZIO.serviceWithZIO[Redis](_.set(i, i))))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
execute[LaserDiscClient](c => items.traverse_(i => c.send(cmd.get[String](Key.unsafeFrom(i)))))
}
@Benchmark
def rediculous(): Unit =
execute[RediculousClient](c => items.traverse_(i => RedisCommands.get[RedisIO](i).run(c)))
@Benchmark
def redis4cats(): Unit =
execute[Redis4CatsClient[String]](c => items.traverse_(i => c.get(i)))
@Benchmark
def zio(): Unit = execute(
ZIO.serviceWithZIO[Redis](redis => ZIO.foreachDiscard(items)(redis.get(_).returning[String]))
)
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.strings
import cats.instances.list._
import cats.syntax.foldable._
import io.chrisdavenport.rediculous.{RedisCommands, RedisIO}
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class GetBitBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(ZIO.foreachDiscard(items)(i => ZIO.serviceWithZIO[Redis](_.set(i, i))))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
execute[LaserDiscClient](c => items.traverse_(i => c.send(cmd.getbit(Key.unsafeFrom(i), PosLong.unsafeFrom(0L)))))
}
@Benchmark
def rediculous(): Unit =
execute[RediculousClient](c => items.traverse_(i => RedisCommands.getbit[RedisIO](i, 0L).run(c)))
@Benchmark
def redis4cats(): Unit =
execute[Redis4CatsClient[String]](c => items.traverse_(i => c.getBit(i, 0L)))
@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(i => ZIO.serviceWithZIO[Redis](_.getBit(i, 0L))))
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.strings
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class SetBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
@Setup(Level.Trial)
def setup(): Unit =
items = (0 to count).toList.map(_.toString)
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c => items.traverse_(i => c.send(cmd.set(Key.unsafeFrom(i), i))))
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(i => RedisCommands.set[RedisIO](i, i).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(i => c.set(i, i)))
}
@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(i => ZIO.serviceWithZIO[Redis](_.set(i, i))))
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.benchmarks.strings
import org.openjdk.jmh.annotations._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class StrLenBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(ZIO.foreachDiscard(items)(i => ZIO.serviceWithZIO[Redis](_.set(i, i))))
}
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc.fs2._
import _root_.laserdisc.{all => cmd, _}
import cats.instances.list._
import cats.syntax.foldable._
execute[LaserDiscClient](c => items.traverse_(i => c.send(cmd.strlen(Key.unsafeFrom(i)))))
}
@Benchmark
def rediculous(): Unit = {
import cats.implicits._
import io.chrisdavenport.rediculous._
execute[RediculousClient](c => items.traverse_(i => RedisCommands.strlen[RedisIO](i).run(c)))
}
@Benchmark
def redis4cats(): Unit = {
import cats.instances.list._
import cats.syntax.foldable._
execute[Redis4CatsClient[String]](c => items.traverse_(i => c.strLen(i)))
}
@Benchmark
def zio(): Unit = execute(ZIO.serviceWithZIO[Redis](redis => ZIO.foreachDiscard(items)(redis.strLen[String])))
}
......@@ -43,11 +43,10 @@ object EmbeddedRedisSpec extends ZIOSpecDefault {
}
).provideShared(
EmbeddedRedis.layer,
SingleNodeExecutor.layer,
ZLayer.succeed[CodecSupplier](new CodecSupplier {
def get[A: Schema]: BinaryCodec[A] = ProtobufCodec.protobufCodec
}),
Redis.layer
Redis.singleNode
) @@ TestAspect.silentLogging
}
......@@ -33,8 +33,7 @@ object Main extends ZIOAppDefault {
AppConfig.layer,
ContributorsCache.layer,
HttpClientZioBackend.layer(),
Redis.layer,
SingleNodeExecutor.layer,
Redis.singleNode,
ZLayer.succeed[CodecSupplier](new CodecSupplier {
def get[A: Schema]: BinaryCodec[A] = ProtobufCodec.protobufCodec
})
......
......@@ -161,6 +161,11 @@ object Input {
}
}
case object ClientTypeInput extends Input[ClientType] {
def encode(data: ClientType): RespCommand =
RespCommand(RespCommandArgument.Literal("TYPE"), RespCommandArgument.Literal(data.asString))
}
case object ClientPauseModeInput extends Input[ClientPauseMode] {
def encode(data: ClientPauseMode): RespCommand =
RespCommand(RespCommandArgument.Literal(data.asString))
......@@ -652,6 +657,15 @@ object Input {
RespCommand(RespCommandArgument.Literal("ID"), RespCommandArgument.Unknown(data.toString))
}
case object IdsInput extends Input[(Long, List[Long])] {
def encode(data: (Long, List[Long])): RespCommand =
RespCommand(
Chunk.fromIterable(
RespCommandArgument.Literal("ID") +: (data._1 :: data._2).map(id => RespCommandArgument.Unknown(id.toString))
)
)
}
case object UnblockBehaviorInput extends Input[UnblockBehavior] {
def encode(data: UnblockBehavior): RespCommand =
RespCommand(RespCommandArgument.Unknown(data.asString))
......
......@@ -727,10 +727,26 @@ object Output {
}
}
case object ClientInfoOutput extends Output[ClientInfo] {
protected def tryDecode(respValue: RespValue): ClientInfo =
respValue match {
case RespValue.BulkString(s) => ClientInfo.from(s.asString)
case other => throw ProtocolError(s"$other isn't a bulk string")
}
}
case object ClientListOutput extends Output[Chunk[ClientInfo]] {
protected def tryDecode(respValue: RespValue): Chunk[ClientInfo] =
respValue match {
case RespValue.BulkString(s) => ClientInfo.from(s.asString.split("\r\n").filter(_.nonEmpty))
case other => throw ProtocolError(s"$other isn't a bulk string")
}
}
case object ClientTrackingInfoOutput extends Output[ClientTrackingInfo] {
protected def tryDecode(respValue: RespValue): ClientTrackingInfo =
respValue match {
case RespValue.NullArray => throw ProtocolError(s"Array must not be empty")
case RespValue.NullArray => throw ProtocolError("Array must not be empty")
case RespValue.Array(values) if values.length % 2 == 0 =>
val fields = values.toList
.grouped(2)
......
......@@ -17,6 +17,7 @@
package zio.redis
import zio._
import zio.redis.internal._
trait Redis
extends api.Connection
......@@ -33,7 +34,16 @@ trait Redis
with api.Cluster
object Redis {
lazy val layer: URLayer[RedisExecutor with CodecSupplier, Redis] =
lazy val cluster: ZLayer[CodecSupplier & RedisClusterConfig, RedisError, Redis] =
ClusterExecutor.layer >>> makeLayer
lazy val local: ZLayer[CodecSupplier, RedisError.IOError, Redis] =
SingleNodeExecutor.local >>> makeLayer
lazy val singleNode: ZLayer[CodecSupplier & RedisConfig, RedisError.IOError, Redis] =
SingleNodeExecutor.layer >>> makeLayer
private def makeLayer: URLayer[CodecSupplier & RedisExecutor, Redis] =
ZLayer {
for {
codecSupplier <- ZIO.service[CodecSupplier]
......
......@@ -20,7 +20,7 @@ import zio.redis.Input._
import zio.redis.Output.{ChunkOutput, ClusterPartitionOutput, UnitOutput}
import zio.redis._
import zio.redis.api.Cluster.{AskingCommand, ClusterSetSlots, ClusterSlots}
import zio.redis.internal.{RedisCommand, RedisEnvironment}
import zio.redis.internal.{RedisCommand, RedisEnvironment, RedisExecutor}
import zio.redis.options.Cluster.SetSlotSubCommand._
import zio.redis.options.Cluster.{Partition, Slot}
import zio.{Chunk, IO}
......
......@@ -91,6 +91,19 @@ trait Connection extends RedisEnvironment {
command.run(())
}
/**
* The command returns information and statistics about the current client connection in a mostly human readable
* format.
*
* @return
* information and statistics about the current client
*/
final def clientInfo: IO[RedisError, ClientInfo] = {
val command = RedisCommand(ClientInfo, NoInput, ClientInfoOutput, executor)
command.run(())
}
/**
* Closes a given client connection with the specified address
*
......@@ -131,6 +144,32 @@ trait Connection extends RedisEnvironment {
command.run(filters)
}
/**
* The command returns information and statistics about the client connections server in a mostly human readable
* format.
*
* @param clientType
* filters the list by client's type
* @param clientIds
* filters the list by client IDs
* @return
* a chunk of information and statistics about clients
*/
final def clientList(
clientType: Option[ClientType] = None,
clientIds: Option[(Long, List[Long])] = None
): IO[RedisError, Chunk[ClientInfo]] = {
val command =
RedisCommand(
ClientList,
Tuple2(OptionalInput(ClientTypeInput), OptionalInput(IdsInput)),
ClientListOutput,
executor
)
command.run((clientType, clientIds))
}
/**
* Returns the name of the current connection as set by clientSetName
*
......@@ -351,7 +390,9 @@ private[redis] object Connection {
final val Auth = "AUTH"
final val ClientCaching = "CLIENT CACHING"
final val ClientId = "CLIENT ID"
final val ClientInfo = "CLIENT INFO"
final val ClientKill = "CLIENT KILL"
final val ClientList = "CLIENT LIST"
final val ClientGetName = "CLIENT GETNAME"
final val ClientGetRedir = "CLIENT GETREDIR"
final val ClientUnpause = "CLIENT UNPAUSE"
......
......@@ -14,39 +14,19 @@
* limitations under the License.
*/
package zio.redis.benchmarks.lists
package zio.redis.internal
import org.openjdk.jmh.annotations._
import zio._
import zio.redis._
import zio.redis.benchmarks._
import zio.{Scope => _, _}
import zio.redis.options.Cluster.{Partition, Slot}
import java.util.concurrent.TimeUnit
private[redis] final case class ClusterConnection(
partitions: Chunk[Partition],
executors: Map[RedisUri, ExecutorScope],
slots: Map[Slot, RedisUri]
) {
def executor(slot: Slot): Option[RedisExecutor] = executors.get(slots(slot)).map(_.executor)
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15)
@Warmup(iterations = 15)
@Fork(2)
class LPosBenchmarks extends BenchmarkRuntime {
@Param(Array("500"))
var count: Int = _
private var items: List[String] = _
private val key = "test-list"
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(ZIO.serviceWithZIO[Redis](_.rPush(key, items.head, items.tail: _*).unit))
}
@TearDown(Level.Trial)
def tearDown(): Unit =
execute(ZIO.serviceWithZIO[Redis](_.del(key).unit))
@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(i => ZIO.serviceWithZIO[Redis](_.lPos[String, String](key, i))))
def addExecutor(uri: RedisUri, es: ExecutorScope): ClusterConnection =
copy(executors = executors + (uri -> es))
}
......@@ -14,22 +14,23 @@
* limitations under the License.
*/
package zio.redis
package zio.redis.internal
import zio._
import zio.redis.ClusterExecutor._
import zio.redis._
import zio.redis.api.Cluster.AskingCommand
import zio.redis.internal.{RedisConnection, RespCommand, RespCommandArgument, RespValue}
import zio.redis.options.Cluster._
import java.io.IOException
final class ClusterExecutor private (
private[redis] final class ClusterExecutor private (
clusterConnection: Ref.Synchronized[ClusterConnection],
config: RedisClusterConfig,
scope: Scope.Closeable
) extends RedisExecutor {
import ClusterExecutor._
def execute(command: RespCommand): IO[RedisError, RespValue] = {
def execute(keySlot: Slot) =
......@@ -93,7 +94,7 @@ final class ClusterExecutor private (
}
}
object ClusterExecutor {
private[redis] object ClusterExecutor {
lazy val layer: ZLayer[RedisClusterConfig, RedisError, RedisExecutor] =
ZLayer.scoped {
......@@ -106,7 +107,7 @@ object ClusterExecutor {
} yield executor
}
private[redis] def create(
def create(
config: RedisClusterConfig,
scope: Scope.Closeable
): ZIO[Scope, RedisError, ClusterExecutor] =
......@@ -148,16 +149,15 @@ object ClusterExecutor {
_ <- layerScope.addFinalizerExit(closableScope.close(_))
} yield ExecutorScope(executor, closableScope)
private def redis(address: RedisUri) = {
val executorLayer = ZLayer.succeed(RedisConfig(address.host, address.port)) >>> SingleNodeExecutor.layer
val codecLayer = ZLayer.succeed[CodecSupplier](CodecSupplier.utf8)
val redisLayer = executorLayer ++ codecLayer >>> Redis.layer
private def redis(address: RedisUri) =
for {
closableScope <- Scope.make
configLayer = ZLayer.succeed(RedisConfig(address.host, address.port))
supplierLayer = ZLayer.succeed(CodecSupplier.utf8)
redisLayer = ZLayer.make[Redis](configLayer, supplierLayer, Redis.singleNode)
layer <- closableScope.extend[Any](redisLayer.memoize)
_ <- logScopeFinalizer("Temporary redis connection is closed")
} yield (layer, closableScope)
}
private def slotAddress(partitions: Chunk[Partition]) =
partitions.flatMap { p =>
......@@ -166,6 +166,7 @@ object ClusterExecutor {
private final val CusterKeyExecutorError =
RedisError.IOError(new IOException("Executor doesn't found. No way to dispatch this command to Redis Cluster"))
private final val CusterConnectionError =
RedisError.IOError(new IOException("The connection to cluster has been failed. Can't reach a single startup node."))
}
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* 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 zio.redis.internal
import zio.Scope
private[redis] final case class ExecutorScope(executor: RedisExecutor, scope: Scope.Closeable)
......@@ -16,7 +16,7 @@
package zio.redis.internal
import zio.redis.{CodecSupplier, RedisExecutor}
import zio.redis.CodecSupplier
import zio.schema.Schema
import zio.schema.codec.BinaryCodec
......
......@@ -14,11 +14,11 @@
* limitations under the License.
*/
package zio.redis
package zio.redis.internal
import zio.IO
import zio.redis.internal.{RespCommand, RespValue}
import zio.redis.RedisError
trait RedisExecutor {
private[redis] def execute(command: RespCommand): IO[RedisError, RespValue]
private[redis] trait RedisExecutor {
def execute(command: RespCommand): IO[RedisError, RespValue]
}
......@@ -14,13 +14,13 @@
* limitations under the License.
*/
package zio.redis
package zio.redis.internal
import zio._
import zio.redis.SingleNodeExecutor._
import zio.redis.internal.{RedisConnection, RespCommand, RespValue}
import zio.redis.internal.SingleNodeExecutor._
import zio.redis.{RedisConfig, RedisError}
final class SingleNodeExecutor private (
private[redis] final class SingleNodeExecutor private (
connection: RedisConnection,
requests: Queue[Request],
responses: Queue[Promise[RedisError, RespValue]]
......@@ -70,20 +70,14 @@ final class SingleNodeExecutor private (
}
object SingleNodeExecutor {
private[redis] object SingleNodeExecutor {
lazy val layer: ZLayer[RedisConfig, RedisError.IOError, RedisExecutor] =
RedisConnection.layer >>> makeLayer
lazy val local: ZLayer[Any, RedisError.IOError, RedisExecutor] =
RedisConnection.local >>> makeLayer
private final case class Request(command: Chunk[RespValue.BulkString], promise: Promise[RedisError, RespValue])
private final val True: Any => Boolean = _ => true
private final val RequestQueueSize = 16
private[redis] def create(connection: RedisConnection): URIO[Scope, SingleNodeExecutor] =
def create(connection: RedisConnection): URIO[Scope, SingleNodeExecutor] =
for {
requests <- Queue.bounded[Request](RequestQueueSize)
responses <- Queue.unbounded[Promise[RedisError, RespValue]]
......@@ -92,6 +86,12 @@ object SingleNodeExecutor {
_ <- logScopeFinalizer(s"$executor Node Executor is closed")
} yield executor
private final case class Request(command: Chunk[RespValue.BulkString], promise: Promise[RedisError, RespValue])
private final val True: Any => Boolean = _ => true
private final val RequestQueueSize = 16
private def makeLayer: ZLayer[RedisConnection, RedisError.IOError, RedisExecutor] =
ZLayer.scoped(ZIO.serviceWithZIO[RedisConnection](create))
}
......@@ -16,13 +16,16 @@
package zio.redis
import cats.effect.{IO => CIO}
import dev.profunktor.redis4cats.RedisCommands
import io.chrisdavenport.rediculous
import laserdisc.fs2.RedisClient
import zio._
package object internal {
private[redis] def logScopeFinalizer(msg: String): URIO[Scope, Unit] =
for {
scope <- ZIO.scope
_ <- scope.addFinalizerExit {
case Exit.Success(_) => ZIO.logTrace(s"$msg with success")
case Exit.Failure(th) => ZIO.logTraceCause(s"$msg with failure", th)
}
} yield ()
package object benchmarks {
type Redis4CatsClient[A] = RedisCommands[CIO, String, A]
type LaserDiscClient = RedisClient[CIO]
type RediculousClient = rediculous.RedisConnection[CIO]
}
......@@ -16,30 +16,16 @@
package zio.redis.options
import zio.redis.{RedisExecutor, RedisUri}
import zio.{Chunk, Scope}
import zio.Chunk
import zio.redis.RedisUri
object Cluster {
private[redis] final val SlotsAmount = 16384
final case class ExecutorScope(executor: RedisExecutor, scope: Scope.Closeable)
final case class ClusterConnection(
partitions: Chunk[Partition],
executors: Map[RedisUri, ExecutorScope],
slots: Map[Slot, RedisUri]
) {
def executor(slot: Slot): Option[RedisExecutor] = executors.get(slots(slot)).map(_.executor)
def addExecutor(uri: RedisUri, es: ExecutorScope): ClusterConnection =
copy(executors = executors + (uri -> es))
}
final case class Slot(number: Long) extends AnyVal
object Slot {
val Default: Slot = Slot(1)
final val Default: Slot = Slot(1)
}
final case class Node(id: String, address: RedisUri)
......
......@@ -16,53 +16,67 @@
package zio.redis.options
import zio.Duration
import zio.{Chunk, Duration}
import java.net.InetAddress
import scala.collection.compat._
trait Connection {
sealed case class Address(ip: InetAddress, port: Int) {
private[redis] final def asString: String = s"${ip.getHostAddress}:$port"
}
object Address {
private[redis] final def fromString(addr: String): Option[Address] =
addr.split(":").toList match {
case ip :: port :: Nil => port.toIntOption.map(new Address(InetAddress.getByName(ip), _))
case _ => None
}
}
sealed case class ClientEvents(readable: Boolean = false, writable: Boolean = false)
sealed trait ClientFlag
object ClientFlag {
case object ToBeClosedAsap extends ClientFlag
case object Blocked extends ClientFlag
case object ToBeClosedAfterReply extends ClientFlag
case object WatchedKeysModified extends ClientFlag
case object IsMaster extends ClientFlag
case object MonitorMode extends ClientFlag
case object PubSub extends ClientFlag
case object ReadOnlyMode extends ClientFlag
case object Replica extends ClientFlag
case object Unblocked extends ClientFlag
case object UnixDomainSocket extends ClientFlag
case object MultiExecContext extends ClientFlag
case object KeysTrackingEnabled extends ClientFlag
case object Blocked extends ClientFlag
case object BroadcastTrackingMode extends ClientFlag
case object IsMaster extends ClientFlag
case object KeysTrackingEnabled extends ClientFlag
case object MonitorMode extends ClientFlag
case object MultiExecContext extends ClientFlag
case object PubSub extends ClientFlag
case object ReadOnlyMode extends ClientFlag
case object Replica extends ClientFlag
case object ToBeClosedAfterReply extends ClientFlag
case object ToBeClosedAsap extends ClientFlag
case object TrackingTargetClientInvalid extends ClientFlag
case object BroadcastTrackingMode extends ClientFlag
case object Unblocked extends ClientFlag
case object UnixDomainSocket extends ClientFlag
case object WatchedKeysModified extends ClientFlag
private[redis] lazy val Flags =
Map(
'A' -> ClientFlag.ToBeClosedAsap,
'b' -> ClientFlag.Blocked,
'B' -> ClientFlag.BroadcastTrackingMode,
'c' -> ClientFlag.ToBeClosedAfterReply,
'd' -> ClientFlag.WatchedKeysModified,
'M' -> ClientFlag.IsMaster,
'O' -> ClientFlag.MonitorMode,
'P' -> ClientFlag.PubSub,
'r' -> ClientFlag.ReadOnlyMode,
'R' -> ClientFlag.TrackingTargetClientInvalid,
'S' -> ClientFlag.Replica,
't' -> ClientFlag.KeysTrackingEnabled,
'u' -> ClientFlag.Unblocked,
'U' -> ClientFlag.UnixDomainSocket,
'x' -> ClientFlag.MultiExecContext
)
}
sealed case class ClientInfo(
id: Long,
id: Option[Long] = None,
name: Option[String] = None,
address: Option[Address] = None,
localAddress: Option[Address] = None,
......@@ -71,9 +85,9 @@ trait Connection {
idle: Option[Duration] = None,
flags: Set[ClientFlag] = Set.empty,
databaseId: Option[Long] = None,
subscriptions: Int = 0,
patternSubscriptions: Int = 0,
multiCommands: Int = 0,
subscriptions: Option[Int] = None,
patternSubscriptions: Option[Int] = None,
multiCommands: Option[Int] = None,
queryBufferLength: Option[Int] = None,
queryBufferFree: Option[Int] = None,
outputBufferLength: Option[Int] = None,
......@@ -87,6 +101,42 @@ trait Connection {
user: Option[String] = None
)
object ClientInfo {
private[redis] final def from(line: String): ClientInfo = {
val data = line.trim.split(" ").map(_.split("=").toList).collect { case k :: v :: Nil => k -> v }.toMap
val events = data.get("events")
new ClientInfo(
id = data.get("id").flatMap(_.toLongOption),
name = data.get("name"),
address = data.get("addr").flatMap(Address.fromString),
localAddress = data.get("laddr").flatMap(Address.fromString),
fileDescriptor = data.get("fd").flatMap(_.toLongOption),
age = data.get("age").flatMap(_.toLongOption).map(Duration.fromSeconds),
idle = data.get("idle").flatMap(_.toLongOption).map(Duration.fromSeconds),
flags = data
.get("flags")
.fold(Set.empty[ClientFlag])(_.foldLeft(Set.empty[ClientFlag])((fs, f) => fs ++ ClientFlag.Flags.get(f))),
databaseId = data.get("id").flatMap(_.toLongOption),
subscriptions = data.get("sub").flatMap(_.toIntOption),
patternSubscriptions = data.get("psub").flatMap(_.toIntOption),
multiCommands = data.get("multi").flatMap(_.toIntOption),
queryBufferLength = data.get("qbuf").flatMap(_.toIntOption),
queryBufferFree = data.get("qbuf-free").flatMap(_.toIntOption),
outputListLength = data.get("oll").flatMap(_.toIntOption),
outputBufferMem = data.get("omem").flatMap(_.toLongOption),
events = ClientEvents(readable = events.exists(_.contains("r")), writable = events.exists(_.contains("w"))),
lastCommand = data.get("cmd"),
argvMemory = data.get("argv-mem").flatMap(_.toLongOption),
totalMemory = data.get("total-mem").flatMap(_.toLongOption),
redirectionClientId = data.get("redir").flatMap(_.toLongOption),
user = data.get("user")
)
}
private[redis] final def from(lines: Array[String]): Chunk[ClientInfo] =
Chunk.fromArray(lines.map(from))
}
sealed trait ClientKillFilter
object ClientKillFilter {
......@@ -156,10 +206,10 @@ trait Connection {
sealed trait ClientType { self =>
private[redis] final def asString: String =
self match {
case ClientType.Normal => "normal"
case ClientType.Master => "master"
case ClientType.Replica => "replica"
case ClientType.PubSub => "pubsub"
case ClientType.Normal => "NORMAL"
case ClientType.Master => "MASTER"
case ClientType.Replica => "REPLICA"
case ClientType.PubSub => "PUBSUB"
}
}
......
......@@ -61,8 +61,6 @@ trait Streams {
counter: Long
)
sealed case class Group[G, C](group: G, consumer: C)
case object NoAck {
private[redis] def asString: String = "NOACK"
}
......
......@@ -28,13 +28,4 @@ package object redis
with options.Scripting {
type Id[+A] = A
private[redis] def logScopeFinalizer(msg: String): URIO[Scope, Unit] =
for {
scope <- ZIO.scope
_ <- scope.addFinalizerExit {
case Exit.Success(_) => ZIO.logTrace(s"$msg with success")
case Exit.Failure(th) => ZIO.logTraceCause(s"$msg with failure", th)
}
} yield ()
}
此差异已折叠。