Sets API

Purely functional interface for the Sets API.

Set Commands usage

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

import cats.effect.IO

val testKey = "foos"

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

val showResult: Set[String] => IO[Unit] = x => putStrLn(s"$testKey members: $x")

commandsApi.use { redis => // SetCommands[IO, String, String]
  for {
    x <- redis.sMembers(testKey)
    _ <- showResult(x)
    _ <- redis.sAdd(testKey, "set value")
    y <- redis.sMembers(testKey)
    _ <- showResult(y)
    _ <- redis.sCard(testKey).flatMap(s => putStrLn(s"size: ${s.toString}"))
    _ <- redis.sRem("non-existing", "random")
    w <- redis.sMembers(testKey)
    _ <- showResult(w)
    _ <- redis.sRem(testKey, "set value")
    z <- redis.sMembers(testKey)
    _ <- showResult(z)
    _ <- redis.sCard(testKey).flatMap(s => putStrLn(s"size: ${s.toString}"))
  } yield ()
}