Hashes API
Purely functional interface for the Hashes API.
Hash Commands usage
Once you have acquired a connection you can start using it:
import cats.effect.IO
val testKey = "foo"
val testField = "bar"
def putStrLn(str: String): IO[Unit] = IO(println(str))
val showResult: Option[String] => IO[Unit] =
_.fold(putStrLn(s"Not found key: $testKey | field: $testField"))(s => putStrLn(s))
commandsApi.use { redis => // HashCommands[IO, String, String]
for {
x <- redis.hGet(testKey, testField)
_ <- showResult(x)
_ <- redis.hSet(testKey, testField, "some value")
y <- redis.hGet(testKey, testField)
_ <- showResult(y)
_ <- redis.hSetNx(testKey, testField, "should not happen")
w <- redis.hGet(testKey, testField)
_ <- showResult(w)
_ <- redis.hDel(testKey, testField)
z <- redis.hGet(testKey, testField)
_ <- showResult(z)
} yield ()
}