diff --git a/docs/index.md b/docs/index.md index 4caf7f4..25b2110 100644 --- a/docs/index.md +++ b/docs/index.md @@ -14,14 +14,15 @@ libraryDependencies ++= Seq( ``` -```scala +```scala mdoc import io.chrisdavenport.rediculous._ -import cats.implicits._ +import cats.syntax.all._ import cats.effect._ -import fs2.io.tcp._ -import java.net.InetSocketAddress +import cats.effect.std.Console +import fs2.io.net._ import fs2._ import scala.concurrent.duration._ +import com.comcast.ip4s._ // Mimics 150 req/s load with 4 operations per request. // Completes 1,000,000 redis operations @@ -30,15 +31,19 @@ object BasicExample extends IOApp { def run(args: List[String]): IO[ExitCode] = { val r = for { - blocker <- Blocker[IO] - sg <- SocketGroup[IO](blocker) - // maxQueued: How many elements before new submissions semantically block. Tradeoff of memory to queue jobs. + // maxQueued: How many elements before new submissions semantically block. Tradeoff of memory to queue jobs. // Default 1000 is good for small servers. But can easily take 100,000. // workers: How many threads will process pipelined messages. - connection <- RedisConnection.queued[IO](sg, "localhost", 6379, maxQueued = 10000, workers = 2) + connection <- RedisConnection + .queued[IO] + .withHost(Host.fromString("localhost").get) + .withPort(port"6379") + .withMaxQueued(10000) + .withWorkers(2) + .build } yield connection - r.use {client => + r.use { client => val r = ( RedisCommands.ping[Redis[IO, *]], RedisCommands.get[Redis[IO, *]]("foo"), @@ -46,24 +51,30 @@ object BasicExample extends IOApp { RedisCommands.get[Redis[IO, *]]("foo") ).parTupled - val r2= List.fill(10)(r.run(client)).parSequence.map{_.flatMap{ - case (_,_,_,_) => List((), (), (), ()) - }} + val r2 = List.fill(10)(r.run(client)).parSequence.map { + _.flatMap { case (_, _, _, _) => + List((), (), (), ()) + } + } - val now = IO(java.time.Instant.now) + val now = Clock[IO].realTimeInstant ( now, - Stream(()).covary[IO].repeat.map(_ => Stream.evalSeq(r2)).parJoin(15).take(1000000).compile.drain, + Stream(()) + .covary[IO] + .repeat + .map(_ => Stream.evalSeq(r2)) + .parJoin(15) + .take(1000000) + .compile + .drain, now - ).mapN{ - case (before, _, after) => (after.toEpochMilli() - before.toEpochMilli()).millis - }.flatMap{ duration => - IO(println(s"Operation took ${duration}")) + ).mapN { case (before, _, after) => + (after.toEpochMilli() - before.toEpochMilli()).millis + }.flatMap { duration => + Console[IO].println(s"Operation took ${duration}") } - } >> - IO.pure(ExitCode.Success) - + }.as(ExitCode.Success) } - } ```