Bitmap Commands
Bitmaps are string values treated as arrays of bits. They’re efficient for storing binary flags and performing bitwise operations.SETBIT
Set or clear the bit at a specific offset in the string value. Syntax:key: The key holding the bitmapoffset: Bit position (0-based, u64)value: 0 or 1
offset
Time complexity: O(1)
Example:
GETBIT
Get the bit value at a specific offset in the string value. Syntax:key: The key holding the bitmapoffset: Bit position (0-based, u64)
offset, or 0 if the key doesn’t exist or offset is beyond the string length
Time complexity: O(1)
Example:
BITCOUNT
Count the number of set bits (1s) in a string. Syntax:key: The key holding the bitmapstart(optional): Start offset (can be negative for reverse indexing)end(optional): End offset (inclusive, can be negative)BYTE|BIT(optional): Interpret offsets as byte (default) or bit positions
BITOP
Perform bitwise operations between strings. Syntax:operation: AND, OR, XOR, or NOTdestkey: Destination key for the resultkey: One or more source keys (NOT accepts only one source)
BITPOS
Find the first bit set to 0 or 1 in a string. Syntax:key: The key holding the bitmapbit: 0 or 1 (the bit value to search for)start(optional): Start offset (can be negative)end(optional): End offset (inclusive, can be negative)BYTE|BIT(optional): Interpret offsets as byte (default) or bit positions
BITFIELD
Perform arbitrary bit field integer operations on strings. Syntax:key: The key holding the bitmapGET encoding offset: Read a signed/unsigned integer at offsetSET encoding offset value: Set a signed/unsigned integer at offsetINCRBY encoding offset increment: Increment a signed/unsigned integer at offsetOVERFLOW mode: Set overflow behavior (WRAP, SAT, or FAIL)
i<bits> for signed, u<bits> for unsigned (e.g., i8, u16)
Offset format: Absolute bit offset or #N for type-scaled offset (multiplied by encoding width)
Return value:
Array reply: array of integers for each GET, SET, or INCRBY subcommand. SET returns the old value, INCRBY returns the new value. Operations with OVERFLOW FAIL that fail return nil.
Time complexity: O(1) for each subcommand
Example:
HyperLogLog Commands
HyperLogLog is a probabilistic data structure for counting unique elements with minimal memory overhead (~12KB per key). It provides approximate cardinality with ~0.81% standard error.PFADD
Add elements to a HyperLogLog. Syntax:key: The HyperLogLog keyelement: One or more elements to add
PFCOUNT
Return the approximated cardinality of a HyperLogLog. Syntax:key: One or more HyperLogLog keys. When multiple keys are specified, returns the cardinality of the union.
PFMERGE
Merge multiple HyperLogLogs into one. Syntax:destkey: Destination HyperLogLog key (will be created or overwritten)sourcekey: One or more source HyperLogLog keys to merge
Geospatial Commands
Geospatial commands store and query geographic coordinates using sorted sets with geohash encoding.GEOADD
Add one or more geospatial items (longitude, latitude, member) to a key. Syntax:key: The geospatial index key (stored as a sorted set)NX: Only add new elements, don’t update existing onesXX: Only update existing elements, don’t add new onesCH: Return the count of changed elements instead of added elementslongitude: Longitude coordinate (-180 to 180)latitude: Latitude coordinate (-85.05112878 to 85.05112878)member: Member name
GEODIST
Return the distance between two members of a geospatial index. Syntax:key: The geospatial index keymember1: First member namemember2: Second member nameunit(optional): Distance unit - m (meters, default), km (kilometers), ft (feet), mi (miles)
GEOHASH
Return geohash strings for one or more members. Syntax:key: The geospatial index keymember: One or more member names
GEOPOS
Return longitude and latitude of one or more members. Syntax:key: The geospatial index keymember: One or more member names
GEOSEARCH
Search for members within a radius from a center point. Syntax:key: The geospatial index keyFROMMEMBER member: Search from an existing member’s positionFROMLONLAT longitude latitude: Search from a longitude/latitude pointBYRADIUS radius unit: Search within a radius (m, km, ft, mi)ASC|DESC(optional): Sort results by distance ascending or descendingCOUNT count(optional): Limit the number of resultsWITHCOORD: Include coordinates in the resultWITHDIST: Include distance from center in the resultWITHHASH: Include geohash integer in the result
Blocking Commands
Blocking commands wait for data to become available on one or more keys. In Kora’s implementation, these commands perform an immediate non-blocking check and return nil if no data is available (timeout=0 behavior).BLPOP
Remove and return the first element from the first non-empty list, or block until one is available. Syntax:key: One or more list keys to check in ordertimeout: Timeout in seconds (Kora treats this as a non-blocking check regardless of value)
BRPOP
Remove and return the last element from the first non-empty list, or block until one is available. Syntax:key: One or more list keys to check in ordertimeout: Timeout in seconds (Kora treats this as a non-blocking check regardless of value)
BLMOVE
Pop an element from a source list and push it to a destination list, or block until an element is available. Syntax:source: Source list keydestination: Destination list key- First
LEFT|RIGHT: Pop from LEFT (head) or RIGHT (tail) of source - Second
LEFT|RIGHT: Push to LEFT (head) or RIGHT (tail) of destination timeout: Timeout in seconds (Kora treats this as a non-blocking check regardless of value)
BZPOPMIN
Remove and return the member with the lowest score from the first non-empty sorted set. Syntax:key: One or more sorted set keys to check in ordertimeout: Timeout in seconds (Kora treats this as a non-blocking check regardless of value)
BZPOPMAX
Remove and return the member with the highest score from the first non-empty sorted set. Syntax:key: One or more sorted set keys to check in ordertimeout: Timeout in seconds (Kora treats this as a non-blocking check regardless of value)
Object Inspection Commands
These commands provide introspection into key metadata and internal representation.OBJECT ENCODING
Return the internal encoding used to store the value at a key. Syntax:key: The key to inspect
embstr: Small string stored inlineraw: Heap-allocated stringint: Integer valuelinkedlist: List structurehashtable: Hash or set structureunknown: Other types
OBJECT FREQ
Return the access frequency counter (LFU) for a key. Syntax:key: The key to inspect
OBJECT IDLETIME
Return the idle time of a key (seconds since last access). Syntax:key: The key to inspect
OBJECT REFCOUNT
Return the reference count of a key. Syntax:key: The key to inspect
Notes
Bitmap Operations
- Bitmaps are stored as string values and automatically expanded when accessing bits beyond the current length
- BITFIELD supports integers up to 64 bits (i64/u64)
- All bitmap operations maintain byte alignment internally
HyperLogLog Implementation
- Kora uses a fixed 12KB HyperLogLog register size per key
- Standard error rate: ~0.81%
- Memory efficient for counting millions of unique elements
Geospatial Storage
- Coordinates are stored as scores in sorted sets using geohash encoding
- Longitude: -180 to 180 degrees
- Latitude: -85.05112878 to 85.05112878 degrees (Mercator projection limits)
- Distance calculations use the Haversine formula
Blocking Commands Behavior
- Kora implements blocking commands as immediate non-blocking checks
- This means they will return immediately with available data or nil
- True blocking with timeout support may be added in future versions
Object Inspection
- These commands are useful for debugging and understanding Kora’s internal storage
- LFU counters are only maintained when memory limits are configured
- Encoding information can help optimize memory usage