diff options
author | Ozan Tezcan <ozantezcan@gmail.com> | 2023-04-09 12:07:32 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-09 12:07:32 +0300 |
commit | e55568edb58c1437d6a84e1baa103dcf5b6153ef (patch) | |
tree | 04377f49bbdbba0be4c6e5514a0a274ec8b05d89 /src/listpack_malloc.h | |
parent | f263b6daf3a2672acc383dc34ed1ff1fe19da5a7 (diff) | |
download | redis-e55568edb58c1437d6a84e1baa103dcf5b6153ef.tar.gz |
Add RM_RdbLoad and RM_RdbSave module API functions (#11852)
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);
```
Diffstat (limited to 'src/listpack_malloc.h')
0 files changed, 0 insertions, 0 deletions