persistence module provides point-in-time binary snapshots of the hash table. A snapshot captures all live key-value pairs — including their expiry timestamps — in a compact binary format with an RDBX magic header. Snapshots complement the AOF log: while the AOF provides durability for individual mutations, snapshots provide faster full restores.
Data structures
RdbStatus
Status codes returned by ht_load.
| Variant | Value | Meaning |
|---|---|---|
RDB_OK | 1 | Snapshot loaded successfully. |
RDB_ERR_OPEN | 2 | fopen failed — file not found or permission denied. |
RDB_ERR_MAGIC | 3 | The file does not begin with the expected RDBX magic bytes. |
Functions
ht_save
Writes the current hash table to a binary snapshot file.
The hash table to snapshot.
Destination file path. Convention is to use the
.rdbx extension, but the API does not enforce it. The engine’s SAVE command appends .rdbx automatically; direct API callers must include it themselves.1 on success, 0 on failure (e.g. if the file cannot be opened for writing).
ht_load
Loads a binary snapshot file into a hash table, replacing the existing one.
Pointer to the hash table pointer.
ht_load frees the old table and replaces *ht with a freshly allocated one populated from the snapshot.Path to the
.rdbx snapshot file to load.RdbStatus value:
| Return value | Condition |
|---|---|
RDB_OK | File opened and all entries loaded. |
RDB_ERR_OPEN | File could not be opened. |
RDB_ERR_MAGIC | File header does not match RDBX. |
Full example
Notes
- The
.rdbxextension is a convention, not enforced by the API. The engine’sSAVEcommand appends it automatically; direct API callers must include it in the filename. ht_loadtakesHashTable **and replaces the pointed-to pointer. The old table is freed inside the function.- Snapshots do not replace the AOF. On startup, load the snapshot first, then replay the AOF to recover mutations written after the last snapshot.