Once you have a BitCommands[F, K, V] instance, you can perform various bitmap operations such as setting/getting bits, performing bitwise OR operations, and using complex bitfield operations.
Common operations include:
setBit(key, offset, value): Sets the bit at the specified offset to the given value.getBit(key, offset): Retrieves the bit value at the specified offset.bitOpOr(dest, src1, src2): Performs a bitwise OR operation between two keys and stores the result in a destination key.bitField(key, *operations): Executes multiple bitfield operations (like SetUnsigned or IncrUnsignedBy) on a single key.
import cats.effect.IO
val testKey = "foo"
val testKey2 = "bar"
val testKey3 = "baz"
commandsApi.use { cmd => // BitCommands[IO, String, String]
for {
a <- cmd.setBit(testKey, 7, 1)
_ <- cmd.setBit(testKey2, 7, 0)
b <- cmd.getBit(testKey, 6)
_ <- cmd.bitOpOr(testKey3, testKey, testKey2)
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)
)
} yield ()
}