Bitmaps API
Purely functional interface for the Bitmaps API.
List Commands usage
Once you have acquired a connection you can start using it:
import cats.effect.IO
val testKey = "foo"
val testKey2 = "bar"
val testKey3 = "baz"
def putStrLn(str: String): IO[Unit] = IO(println(str))
commandsApi.use { cmd => // BitCommands[IO, String, String]
for {
a <- cmd.setBit(testKey, 7, 1)
_ <- cmd.setBit(testKey2, 7, 0)
_ <- putStrLn(s"Set as $a")
b <- cmd.getBit(testKey, 6)
_ <- putStrLn(s"Bit at offset 6 is $b")
_ <- cmd.bitOpOr(testKey3, testKey, testKey2)
_ <- for {
s1 <- cmd.setBit("bitmapsarestrings", 2, 1)
s2 <- cmd.setBit("bitmapsarestrings", 3, 1)
s3 <- cmd.setBit("bitmapsarestrings", 5, 1)
s4 <- cmd.setBit("bitmapsarestrings", 10, 1)
s5 <- cmd.setBit("bitmapsarestrings", 11, 1)
s6 <- cmd.setBit("bitmapsarestrings", 14, 1)
} yield s1 + s2 + s3 + s4 + s5 + s6
bf <- cmd.bitField(
"inmap",
SetUnsigned(2, 1),
SetUnsigned(3, 1),
SetUnsigned(5, 1),
SetUnsigned(10, 1),
SetUnsigned(11, 1),
SetUnsigned(14, 1),
IncrUnsignedBy(14, 1)
)
_ <- putStrLn(s"Via bitfield $bf")
} yield ()
}