MCPcopy Create free account
hub / github.com/F-Stack/f-stack / RM_EmitAOF

Function RM_EmitAOF

app/redis-6.2.6/src/module.c:5038–5082  ·  view source on GitHub ↗

Emits a command into the AOF during the AOF rewriting process. This function * is only called in the context of the aof_rewrite method of data types exported * by a module. The command works exactly like RedisModule_Call() in the way * the parameters are passed, but it does not return anything as the error * handling is performed by Redis itself. */

Source from the content-addressed store, hash-verified

5036 * the parameters are passed, but it does not return anything as the error
5037 * handling is performed by Redis itself. */
5038void RM_EmitAOF(RedisModuleIO *io, const char *cmdname, const char *fmt, ...) {
5039 if (io->error) return;
5040 struct redisCommand *cmd;
5041 robj **argv = NULL;
5042 int argc = 0, flags = 0, j;
5043 va_list ap;
5044
5045 cmd = lookupCommandByCString((char*)cmdname);
5046 if (!cmd) {
5047 serverLog(LL_WARNING,
5048 "Fatal: AOF method for module data type '%s' tried to "
5049 "emit unknown command '%s'",
5050 io->type->name, cmdname);
5051 io->error = 1;
5052 errno = EINVAL;
5053 return;
5054 }
5055
5056 /* Emit the arguments into the AOF in Redis protocol format. */
5057 va_start(ap, fmt);
5058 argv = moduleCreateArgvFromUserFormat(cmdname,fmt,&argc,&flags,ap);
5059 va_end(ap);
5060 if (argv == NULL) {
5061 serverLog(LL_WARNING,
5062 "Fatal: AOF method for module data type '%s' tried to "
5063 "call RedisModule_EmitAOF() with wrong format specifiers '%s'",
5064 io->type->name, fmt);
5065 io->error = 1;
5066 errno = EINVAL;
5067 return;
5068 }
5069
5070 /* Bulk count. */
5071 if (!io->error && rioWriteBulkCount(io->rio,'*',argc) == 0)
5072 io->error = 1;
5073
5074 /* Arguments. */
5075 for (j = 0; j < argc; j++) {
5076 if (!io->error && rioWriteBulkObject(io->rio,argv[j]) == 0)
5077 io->error = 1;
5078 decrRefCount(argv[j]);
5079 }
5080 zfree(argv);
5081 return;
5082}
5083
5084/* --------------------------------------------------------------------------
5085 * ## IO context handling

Callers

nothing calls this directly

Calls 6

lookupCommandByCStringFunction · 0.85
rioWriteBulkCountFunction · 0.85
rioWriteBulkObjectFunction · 0.85
decrRefCountFunction · 0.85
zfreeFunction · 0.70

Tested by

no test coverage detected