Module cdc

Module cdc 

Source
Expand description

Change Data Capture (CDC) Stream support.

Emits mutations to a Redis Stream for external replication agents. The stream key is {redis_prefix}:cdc - each node writes to its own stream. Replication agents tail remote peers’ CDC streams to replicate changes.

§Stream Format

§PUT operation

XADD {prefix}:cdc MAXLEN ~ 100000 *
  op    "PUT"
  key   "uk.nhs.patient.12345"
  hash  "a1b2c3..."                # content_hash for dedup
  data  <zstd(content)>            # compressed payload
  meta  '{"content_type":"json","version":3,"updated_at":1735776000000}'

§DELETE operation

XADD {prefix}:cdc MAXLEN ~ 100000 *
  op    "DEL"
  key   "uk.nhs.patient.12345"

§Compression Strategy

Data is zstd-compressed before writing to the stream, unless it already has zstd magic bytes (to avoid double-compression).

Structs§

CdcEntry
A CDC entry ready to be written to the stream
CdcMeta
Metadata for CDC PUT entries

Enums§

CdcFieldValue
Field value types for CDC entries
CdcOp
CDC operation type

Constants§

CDC_STREAM_SUFFIX
CDC stream key suffix (appended to redis_prefix). Convention: redis_prefix includes trailing colon (e.g., “redsqrl:”). Result: “redsqrl:cdc” or just “cdc” if no prefix.

Functions§

cdc_stream_key
Build the full CDC stream key from an optional prefix
is_zstd_compressed
Check if data appears to be zstd-compressed
maybe_compress
Compress data with zstd, unless it’s already zstd-compressed.
maybe_decompress
Decompress zstd data if it has the magic header, otherwise return as-is.