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
import cats.syntax.all._

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 { cmd => // HashCommands[IO, String, String]
  for {
    x <- cmd.hGet(testKey, testField)
    _ <- showResult(x)
    _ <- cmd.hSet(testKey, testField, "some value")
    y <- cmd.hGet(testKey, testField)
    _ <- showResult(y)
    _ <- cmd.hSetNx(testKey, testField, "should not happen")
    w <- cmd.hGet(testKey, testField)
    _ <- showResult(w)
    _ <- cmd.hDel(testKey, testField)
    z <- cmd.hGet(testKey, testField)
    _ <- showResult(z)
  } yield ()
}