Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[548] Expose Redis operations via Redis trait #727

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ import zio.schema.codec._

object ZIORedisExample extends ZIOAppDefault {
val myApp: ZIO[Redis, RedisError, Unit] = for {
_ <- set("myKey", 8L, Some(1.minutes))
v <- get("myKey").returning[Long]
_ <- Console.printLine(s"Value of myKey: $v").orDie
_ <- hSet("myHash", ("k1", 6), ("k2", 2))
_ <- rPush("myList", 1, 2, 3, 4)
_ <- sAdd("mySet", "a", "b", "a", "c")
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class HDelBenchmarks extends BenchmarkRuntime {
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to size).map(e => e.toString -> e.toString).toList
execute(hSet(key, items.head, items.tail: _*).unit)
execute(ZIO.serviceWithZIO[Redis](_.hSet(key, items.head, items.tail: _*).unit))
}

@Benchmark
Expand All @@ -67,5 +67,5 @@ class HDelBenchmarks extends BenchmarkRuntime {
}

@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(it => hDel(key, it._1)))
def zio(): Unit = execute(ZIO.foreachDiscard(items)(it => ZIO.serviceWithZIO[Redis](_.hDel(key, it._1))))
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class HExistsBenchmarks extends BenchmarkRuntime {
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to size).map(e => e.toString -> e.toString).toList
execute(hSet(key, items.head, items.tail: _*).unit)
execute(ZIO.serviceWithZIO[Redis](_.hSet(key, items.head, items.tail: _*).unit))
}

@Benchmark
Expand Down Expand Up @@ -69,5 +69,5 @@ class HExistsBenchmarks extends BenchmarkRuntime {
}

@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(it => hExists(key, it._1)))
def zio(): Unit = execute(ZIO.foreachDiscard(items)(it => ZIO.serviceWithZIO[Redis](_.hExists(key, it._1))))
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class HGetAllBenchmarks extends BenchmarkRuntime {
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to size).map(e => e.toString -> e.toString).toList
execute(hSet(key, items.head, items.tail: _*).unit)
execute(ZIO.serviceWithZIO[Redis](_.hSet(key, items.head, items.tail: _*).unit))
}

@Benchmark
Expand All @@ -67,5 +67,7 @@ class HGetAllBenchmarks extends BenchmarkRuntime {
}

@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(_ => hGetAll(key).returning[String, String]))
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(_ => ZIO.serviceWithZIO[Redis](_.hGetAll(key).returning[String, String]))
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class HGetBenchmarks extends BenchmarkRuntime {
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to size).map(e => e.toString -> e.toString).toList
execute(hSet(key, items.head, items.tail: _*).unit)
execute(ZIO.serviceWithZIO[Redis](_.hSet(key, items.head, items.tail: _*).unit))
}

@Benchmark
Expand Down Expand Up @@ -68,5 +68,7 @@ class HGetBenchmarks extends BenchmarkRuntime {
}

@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(it => hGet(key, it._1).returning[String]))
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(it => ZIO.serviceWithZIO[Redis](_.hGet(key, it._1).returning[String]))
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class HIncrbyBenchmarks extends BenchmarkRuntime {
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to size).map(e => e.toString -> e.toString).toList
execute(hSet(key, items.head, items.tail: _*).unit)
execute(ZIO.serviceWithZIO[Redis](_.hSet(key, items.head, items.tail: _*).unit))
}

@Benchmark
Expand Down Expand Up @@ -73,5 +73,7 @@ class HIncrbyBenchmarks extends BenchmarkRuntime {
}

@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(it => hIncrBy(key, it._1, increment)))
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(it => ZIO.serviceWithZIO[Redis](_.hIncrBy(key, it._1, increment)))
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class HIncrbyFloatBenchmarks extends BenchmarkRuntime {
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to size).map(e => e.toString -> e.toString).toList
execute(hSet(key, items.head, items.tail: _*).unit)
execute(ZIO.serviceWithZIO[Redis](_.hSet(key, items.head, items.tail: _*).unit))
}

@Benchmark
Expand Down Expand Up @@ -75,5 +75,7 @@ class HIncrbyFloatBenchmarks extends BenchmarkRuntime {
}

@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(it => hIncrByFloat(key, it._1, increment)))
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(it => ZIO.serviceWithZIO[Redis](_.hIncrByFloat(key, it._1, increment)))
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class HKeysBenchmarks extends BenchmarkRuntime {
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to size).map(e => e.toString -> e.toString).toList
execute(hSet(key, items.head, items.tail: _*).unit)
execute(ZIO.serviceWithZIO[Redis](_.hSet(key, items.head, items.tail: _*).unit))
}

@Benchmark
Expand All @@ -67,5 +67,5 @@ class HKeysBenchmarks extends BenchmarkRuntime {
}

@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(_ => hKeys(key).returning[String]))
def zio(): Unit = execute(ZIO.foreachDiscard(items)(_ => ZIO.serviceWithZIO[Redis](_.hKeys(key).returning[String])))
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class HLenBenchmarks extends BenchmarkRuntime {
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to size).map(e => e.toString -> e.toString).toList
execute(hSet(key, items.head, items.tail: _*).unit)
execute(ZIO.serviceWithZIO[Redis](_.hSet(key, items.head, items.tail: _*).unit))
}

@Benchmark
Expand All @@ -67,5 +67,5 @@ class HLenBenchmarks extends BenchmarkRuntime {
}

@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(_ => hLen(key)))
def zio(): Unit = execute(ZIO.foreachDiscard(items)(_ => ZIO.serviceWithZIO[Redis](_.hLen(key))))
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class HMGetBenchmarks extends BenchmarkRuntime {
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to size).map(e => e.toString -> e.toString).toList
execute(hSet(key, items.head, items.tail: _*).unit)
execute(ZIO.serviceWithZIO[Redis](_.hSet(key, items.head, items.tail: _*).unit))
}

@Benchmark
Expand Down Expand Up @@ -68,5 +68,7 @@ class HMGetBenchmarks extends BenchmarkRuntime {
}

@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(it => hmGet(key, it._1).returning[String]))
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(it => ZIO.serviceWithZIO[Redis](_.hmGet(key, it._1).returning[String]))
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ class HMSetBenchmarks extends BenchmarkRuntime {
}

@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(it => hmSet(key, it)))
def zio(): Unit = execute(ZIO.foreachDiscard(items)(it => ZIO.serviceWithZIO[Redis](_.hmSet(key, it))))
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ class HSetBenchmarks extends BenchmarkRuntime {
}

@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(it => hSet(key, it)))
def zio(): Unit = execute(ZIO.foreachDiscard(items)(it => ZIO.serviceWithZIO[Redis](_.hSet(key, it))))
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@ class HSetNxBenchmarks extends BenchmarkRuntime {
}

@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(it => hSetNx(key, it._1, it._2)))
def zio(): Unit = execute(ZIO.foreachDiscard(items)(it => ZIO.serviceWithZIO[Redis](_.hSetNx(key, it._1, it._2))))
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class HStrLenBenchmarks extends BenchmarkRuntime {

def setup(): Unit = {
items = (0 to size).map(e => e.toString -> e.toString).toList
execute(hSet(key, items.head, items.tail: _*).unit)
execute(ZIO.serviceWithZIO[Redis](_.hSet(key, items.head, items.tail: _*).unit))
}
@Benchmark
def laserdisc(): Unit = {
Expand All @@ -66,5 +66,5 @@ class HStrLenBenchmarks extends BenchmarkRuntime {
}

@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(it => hStrLen(key, it._1)))
def zio(): Unit = execute(ZIO.foreachDiscard(items)(it => ZIO.serviceWithZIO[Redis](_.hStrLen(key, it._1))))
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class HValsBenchmarks extends BenchmarkRuntime {
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to size).map(e => e.toString -> e.toString).toList
execute(hSet(key, items.head, items.tail: _*).unit)
execute(ZIO.serviceWithZIO[Redis](_.hSet(key, items.head, items.tail: _*).unit))
}

@Benchmark
Expand All @@ -67,5 +67,5 @@ class HValsBenchmarks extends BenchmarkRuntime {
}

@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(_ => hVals(key).returning[String]))
def zio(): Unit = execute(ZIO.foreachDiscard(items)(_ => ZIO.serviceWithZIO[Redis](_.hVals(key).returning[String])))
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,17 @@ class BlMoveBenchmarks extends BenchmarkRuntime {
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(rPush(key, items.head, items.tail: _*).unit)
execute(ZIO.serviceWithZIO[Redis](_.rPush(key, items.head, items.tail: _*).unit))
}

@TearDown(Level.Trial)
def tearDown(): Unit =
execute(del(key).unit)
execute(ZIO.serviceWithZIO[Redis](_.del(key).unit))

@Benchmark
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(_ => blMove(key, key, Side.Left, Side.Right, 1.second).returning[String])
ZIO.foreachDiscard(items)(_ =>
ZIO.serviceWithZIO[Redis](_.blMove(key, key, Side.Left, Side.Right, 1.second).returning[String])
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class BlPopBenchmarks extends BenchmarkRuntime {
@Setup(Level.Invocation)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(rPush(key, items.head, items.tail: _*).unit)
execute(ZIO.serviceWithZIO[Redis](_.rPush(key, items.head, items.tail: _*).unit))
}

@Benchmark
Expand Down Expand Up @@ -76,5 +76,7 @@ class BlPopBenchmarks extends BenchmarkRuntime {
}

@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(_ => blPop(key)(1.second).returning[String]))
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(_ => ZIO.serviceWithZIO[Redis](_.blPop(key)(1.second).returning[String]))
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class BrPopBenchmarks extends BenchmarkRuntime {
@Setup(Level.Invocation)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(rPush(key, items.head, items.tail: _*).unit)
execute(ZIO.serviceWithZIO[Redis](_.rPush(key, items.head, items.tail: _*).unit))
}

@Benchmark
Expand Down Expand Up @@ -76,5 +76,7 @@ class BrPopBenchmarks extends BenchmarkRuntime {
}

@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(_ => brPop(key)(1.second).returning[String]))
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(_ => ZIO.serviceWithZIO[Redis](_.brPop(key)(1.second).returning[String]))
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ class BrPopLPushBenchmarks extends BenchmarkRuntime {
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(rPush(key, items.head, items.tail: _*).unit)
execute(ZIO.serviceWithZIO[Redis](_.rPush(key, items.head, items.tail: _*).unit))
}

@TearDown(Level.Trial)
def tearDown(): Unit =
execute(del(key).unit)
execute(ZIO.serviceWithZIO[Redis](_.del(key).unit))

@Benchmark
def laserdisc(): Unit = {
Expand Down Expand Up @@ -82,6 +82,6 @@ class BrPopLPushBenchmarks extends BenchmarkRuntime {

@Benchmark
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(_ => brPopLPush(key, key, 1.second).returning[String])
ZIO.foreachDiscard(items)(_ => ZIO.serviceWithZIO[Redis](_.brPopLPush(key, key, 1.second).returning[String]))
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ class LIndexBenchmarks extends BenchmarkRuntime {
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to count).toList
execute(rPush(key, items.head, items.tail: _*).unit)
execute(ZIO.serviceWithZIO[Redis](_.rPush(key, items.head, items.tail: _*).unit))
}

@TearDown(Level.Trial)
def tearDown(): Unit =
execute(del(key).unit)
execute(ZIO.serviceWithZIO[Redis](_.del(key).unit))

@Benchmark
def laserdisc(): Unit = {
Expand Down Expand Up @@ -76,5 +76,7 @@ class LIndexBenchmarks extends BenchmarkRuntime {
}

@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(i => lIndex(key, i.toLong).returning[String]))
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(i => ZIO.serviceWithZIO[Redis](_.lIndex(key, i.toLong).returning[String]))
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ class LInsertBenchmarks extends BenchmarkRuntime {
@Setup(Level.Invocation)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(rPush(key, items.head, items.tail: _*).unit)
execute(ZIO.serviceWithZIO[Redis](_.rPush(key, items.head, items.tail: _*).unit))
}

@TearDown(Level.Invocation)
def tearDown(): Unit =
execute(del(key).unit)
execute(ZIO.serviceWithZIO[Redis](_.del(key).unit))

@Benchmark
def laserdisc(): Unit = {
Expand Down Expand Up @@ -77,5 +77,7 @@ class LInsertBenchmarks extends BenchmarkRuntime {
}

@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(i => lInsert[String, String](key, Position.Before, i, i)))
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(i => ZIO.serviceWithZIO[Redis](_.lInsert[String, String](key, Position.Before, i, i)))
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@ class LLenBenchmarks extends BenchmarkRuntime {
}

@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(_ => lLen[String](key)))
def zio(): Unit = execute(ZIO.foreachDiscard(items)(_ => ZIO.serviceWithZIO[Redis](_.lLen[String](key))))
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,17 @@ class LMoveBenchmarks extends BenchmarkRuntime {
@Setup(Level.Trial)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(rPush(key, items.head, items.tail: _*).unit)
execute(ZIO.serviceWithZIO[Redis](_.rPush(key, items.head, items.tail: _*).unit))
}

@TearDown(Level.Trial)
def tearDown(): Unit =
execute(del(key).unit)
execute(ZIO.serviceWithZIO[Redis](_.del(key).unit))

@Benchmark
def zio(): Unit = execute(
ZIO.foreachDiscard(items)(_ => lMove(key, key, Side.Left, Side.Right).returning[String])
ZIO.foreachDiscard(items)(_ =>
ZIO.serviceWithZIO[Redis](_.lMove(key, key, Side.Left, Side.Right).returning[String])
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class LPopBenchmarks extends BenchmarkRuntime {
@Setup(Level.Invocation)
def setup(): Unit = {
items = (0 to count).toList.map(_.toString)
execute(rPush(key, items.head, items.tail: _*).unit)
execute(ZIO.serviceWithZIO[Redis](_.rPush(key, items.head, items.tail: _*).unit))
}

@Benchmark
Expand Down Expand Up @@ -70,5 +70,5 @@ class LPopBenchmarks extends BenchmarkRuntime {
}

@Benchmark
def zio(): Unit = execute(ZIO.foreachDiscard(items)(_ => lPop(key).returning[String]))
def zio(): Unit = execute(ZIO.foreachDiscard(items)(_ => ZIO.serviceWithZIO[Redis](_.lPop(key).returning[String])))
}
Loading