Redis replication stream parser implemented in Rust.
This module provides a streaming parser for Redis replication protocol. (except for few greeting commands) The parser handles RDB snapshot transfer and command subsequent online command streaming.
The parser main states are:
- WaitingRdb: Initial state, waiting for RDB data
- ReadingRdb: Parsing RDB snapshot
- Streaming: Processing command stream after RDB
This parser is designed to be used internally by Vdr.RedisStream.Replica
Summary
Types
Functions
Create a new streaming replica parser.
Options
:rdb- Boolean, defaulttrue. Iffalse, the parser starts in streaming mode without expecting RDB data. Userdb: falsefor partial resync scenarios where no RDB snapshot will be transferred.
Returns
A parser resource that can be used with data/2.
Feed a chunk of binary data to the replica parser.
The parser will process the data according to its current state:
- In WaitingRdb state: waits for RDB bulk string header
- In ReadingRdb state: parses RDB snapshot and returns commands
- In Streaming state: parses RESP commands from the stream
Parameters
parser- Parser resource fromcreate/0or previousdata/2callchunk- Binary chunk of replication data
Returns
{:ok, commands, new_parser, flags}- Successfully processed chunk, returns parsed commands (may be empty){:error, reason}- Parsing failed
Commands are tuples: {db, command_tuple, raw_command, affected_keys} where:
dbis the database numbercommand_tupleis a parsed command tuple (e.g.,{:set, key, value})raw_commandis the raw command tuple{:generic, args}for logging/debuggingaffected_keysis a list of keys affected by this command
The flags map contains:
:ping-trueif a PING command was encountered during this chunk processing:replconf_getack-trueif a REPLCONF GETACK command was encountered during this chunk processing
Note: PING and REPLCONF commands are not returned as commands - they are signaled via flags only.