Skip to content

Commit

Permalink
Fix documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
gvolpe committed Dec 6, 2020
1 parent 35f0787 commit fd04236
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package dev.profunktor.redis4cats

import java.time.Instant
import java.util.concurrent.TimeoutException

import cats.data.NonEmptyList
import cats.effect._
Expand All @@ -25,7 +26,7 @@ import dev.profunktor.redis4cats.data.KeyScanCursor
import dev.profunktor.redis4cats.effect.Log.NoOp._
import dev.profunktor.redis4cats.effects._
import dev.profunktor.redis4cats.hlist._
import dev.profunktor.redis4cats.pipeline.RedisPipeline
import dev.profunktor.redis4cats.pipeline.{ PipelineError, RedisPipeline }
import dev.profunktor.redis4cats.transactions.RedisTransaction
import io.lettuce.core.GeoArgs
import munit.FunSuite
Expand Down Expand Up @@ -384,13 +385,17 @@ trait TestScenarios { self: FunSuite =>
cmd.set(key1, "osx") :: cmd.get(key3) :: cmd.set(key2, "linux") :: cmd.sIsMember("foo", "bar") :: HNil

val runPipeline =
RedisPipeline(cmd).filterExec(operations).map {
case res1 ~: res2 ~: HNil =>
assertEquals(res1, Some("3"))
assert(!res2)
case tr =>
fail(s"Unexpected result: $tr")
}
RedisPipeline(cmd)
.filterExec(operations)
.map {
case res1 ~: res2 ~: HNil =>
assertEquals(res1, Some("3"))
assert(!res2)
}
.onError {
case PipelineError => fail("[Error] - Pipeline failed")
case _: TimeoutException => fail("[Error] - Timeout")
}

for {
_ <- cmd.set(key3, "3")
Expand Down
26 changes: 16 additions & 10 deletions site/docs/pipelining.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,25 @@ commandsApi.use { cmd => // RedisCommands[IO, String, String]
val getters =
cmd.get(key1).flatTap(showResult(key1)) >>
cmd.get(key2).flatTap(showResult(key2)) >>
cmd.get(key3).flatTap(showResult(key3)) >>
cmd.get(key3).flatTap(showResult(key3))

val operations =
cmd.set(key1, "osx") :: cmd.get(key3) :: cmd.set(key2, "linux") :: cmd.sIsMember("foo", "bar") :: HNil

val runPipeline =
RedisPipeline(cmd).filterExec(operations).map {
case res1 ~: res2 ~: HNil =>
assertEquals(res1, Some("3"))
assert(!res2)
case tr =>
fail(s"Unexpected result: $tr")
}
RedisPipeline(cmd)
.filterExec(operations)
.map {
case res1 ~: res2 ~: HNil =>
assert(res1.contains("3"))
assert(!res2)
}
.onError {
case PipelineError =>
putStrLn("[Error] - Pipeline failed")
case _: TimeoutException =>
putStrLn("[Error] - Timeout")
}

val prog =
for {
Expand All @@ -97,8 +103,8 @@ commandsApi.use { cmd => // RedisCommands[IO, String, String]
v1 <- cmd.get(key1)
v2 <- cmd.get(key2)
} yield {
assertEquals(v1, Some("osx"))
assertEquals(v2, Some("linux"))
assert(v1.contains("osx"))
assert(v2.contains("linux"))
}

getters >> prog >> getters >> putStrLn("keep doing stuff...")
Expand Down

0 comments on commit fd04236

Please sign in to comment.