Strings API

Purely functional interface for the Strings API.

String Commands usage

Once you have acquired a connection you can start using it:

import cats.effect.IO

val usernameKey = "users"

def putStrLn(str: String): IO[Unit] = IO(println(str))

val showResult: Option[String] => IO[Unit] =
  _.fold(putStrLn(s"Not found key: $usernameKey"))(s => putStrLn(s))

commandsApi.use { redis => // StringCommands[IO, String, String]
  for {
    x <- redis.get(usernameKey)
    _ <- showResult(x)
    _ <- redis.set(usernameKey, "gvolpe")
    y <- redis.get(usernameKey)
    _ <- showResult(y)
    _ <- redis.setNx(usernameKey, "should not happen")
    w <- redis.get(usernameKey)
    _ <- showResult(w)
  } yield ()
}