mirror of
https://github.com/redis/redis.git
synced 2026-04-29 10:09:34 -04:00
Add `RM_RdbLoad()` and `RM_RdbSave()` to load/save RDB files from the module API.
In our use case, we have our clustering implementation as a module. As part of this
implementation, the module needs to trigger RDB save operation at specific points.
Also, this module delivers RDB files to other nodes (not using Redis' replication).
When a node receives an RDB file, it should be able to load the RDB. Currently,
there is no module API to save/load RDB files.
This PR adds four new APIs:
```c
RedisModuleRdbStream *RM_RdbStreamCreateFromFile(const char *filename);
void RM_RdbStreamFree(RedisModuleRdbStream *stream);
int RM_RdbLoad(RedisModuleCtx *ctx, RedisModuleRdbStream *stream, int flags);
int RM_RdbSave(RedisModuleCtx *ctx, RedisModuleRdbStream *stream, int flags);
```
The first step is to create a `RedisModuleRdbStream` object. This PR provides a function to
create RedisModuleRdbStream from the filename. (You can load/save RDB with the filename).
In the future, this API can be extended if needed:
e.g., `RM_RdbStreamCreateFromFd()`, `RM_RdbStreamCreateFromSocket()` to save/load
RDB from an `fd` or a `socket`.
Usage:
```c
/* Save RDB */
RedisModuleRdbStream *stream = RedisModule_RdbStreamCreateFromFile("example.rdb");
RedisModule_RdbSave(ctx, stream, 0);
RedisModule_RdbStreamFree(stream);
/* Load RDB */
RedisModuleRdbStream *stream = RedisModule_RdbStreamCreateFromFile("example.rdb");
RedisModule_RdbLoad(ctx, stream, 0);
RedisModule_RdbStreamFree(stream);
```
|
||
|---|---|---|
| .. | ||
| aclcheck.tcl | ||
| async_rm_call.tcl | ||
| auth.tcl | ||
| basics.tcl | ||
| blockedclient.tcl | ||
| blockonbackground.tcl | ||
| blockonkeys.tcl | ||
| cluster.tcl | ||
| cmdintrospection.tcl | ||
| commandfilter.tcl | ||
| datatype.tcl | ||
| datatype2.tcl | ||
| defrag.tcl | ||
| eventloop.tcl | ||
| fork.tcl | ||
| getchannels.tcl | ||
| getkeys.tcl | ||
| hash.tcl | ||
| hooks.tcl | ||
| infotest.tcl | ||
| infra.tcl | ||
| keyspace_events.tcl | ||
| keyspecs.tcl | ||
| list.tcl | ||
| mallocsize.tcl | ||
| misc.tcl | ||
| moduleauth.tcl | ||
| moduleconfigs.tcl | ||
| postnotifications.tcl | ||
| propagate.tcl | ||
| publish.tcl | ||
| rdbloadsave.tcl | ||
| reply.tcl | ||
| scan.tcl | ||
| stream.tcl | ||
| subcommands.tcl | ||
| test_lazyfree.tcl | ||
| testrdb.tcl | ||
| timer.tcl | ||
| usercall.tcl | ||
| zset.tcl | ||