Add AoF routines

master
Mark Nunberg 7 years ago
parent 6a3b796b7a
commit 56b1fbdd31

@ -275,3 +275,19 @@ RedisModuleString **RMUtil_ParseVarArgs(RedisModuleString **argv, int argc, int
*nargs = n;
return argv + 1;
}
void RMUtil_DefaultAofRewrite(RedisModuleIO *aof, RedisModuleString *key, void *value) {
RedisModuleCtx *ctx = RedisModule_GetThreadSafeContext(NULL);
RedisModuleCallReply *rep = RedisModule_Call(ctx, "DUMP", "s", key);
if (rep != NULL && RedisModule_CallReplyType(rep) == REDISMODULE_REPLY_STRING) {
size_t n;
const char *s = RedisModule_CallReplyStringPtr(rep, &n);
RedisModule_EmitAOF(aof, "RESTORE", "slb", key, 0, s, n);
} else {
RedisModule_Log(RedisModule_GetContextFromIO(aof), "warning", "Failed to emit AOF");
}
if (rep != NULL) {
RedisModule_FreeCallReply(rep);
}
RedisModule_FreeThreadSafeContext(ctx);
}

@ -72,6 +72,13 @@ int rmutil_vparseArgs(RedisModuleString **argv, int argc, int offset, const char
RedisModuleString **RMUtil_ParseVarArgs(RedisModuleString **argv, int argc, int offset,
const char *keyword, size_t *nargs);
/**
* Default implementation of an AoF rewrite function that simply calls DUMP/RESTORE
* internally. To use this function, pass it as the .aof_rewrite value in
* RedisModuleTypeMethods
*/
void RMUtil_DefaultAofRewrite(RedisModuleIO *aof, RedisModuleString *key, void *value);
// A single key/value entry in a redis info map
typedef struct {
const char *key;

Loading…
Cancel
Save