Ferricstore.Commands.Bitmap (ferricstore v0.3.2)

Copy Markdown View Source

Handles Redis bitmap commands: SETBIT, GETBIT, BITCOUNT, BITPOS, BITOP.

Each handler takes the uppercased command name, a list of string arguments, and an injected store map. Returns plain Elixir terms — the connection layer handles RESP encoding.

Bitmap commands operate on string values at the bit level. Bits are numbered from the most significant bit (MSB) of the first byte: bit 0 is the MSB of byte 0 (value 128), bit 7 is the LSB of byte 0 (value 1), bit 8 is the MSB of byte 1, and so on. This matches Redis bit ordering.

Since FerricStore uses an append-only Bitcask storage engine, all write operations (SETBIT, BITOP) perform a read-modify-write cycle.

Supported commands

  • SETBIT key offset value — set or clear the bit at offset; returns old bit
  • GETBIT key offset — returns the bit value at offset
  • BITCOUNT key [start end [BYTE|BIT]] — count set bits in a range
  • BITPOS key bit [start [end [BYTE|BIT]]] — find first 0 or 1 bit
  • BITOP operation destkey key [key ...] — bitwise AND/OR/XOR/NOT

Summary

Functions

Handles a bitmap command.

Functions

handle(cmd, args, store)

@spec handle(binary(), [binary()], map()) :: term()

Handles a bitmap command.

Parameters

  • cmd - Uppercased command name (e.g. "SETBIT", "GETBIT")
  • args - List of string arguments
  • store - Injected store map with get, put callbacks

Returns

Plain Elixir term: integer, or {:error, message}.