MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / RM_EmitAOF

Function RM_EmitAOF

src/module.cpp:5147–5191  ·  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

5145 * the parameters are passed, but it does not return anything as the error
5146 * handling is performed by Redis itself. */
5147void RM_EmitAOF(RedisModuleIO *io, const char *cmdname, const char *fmt, ...) {
5148 if (io->error) return;
5149 struct redisCommand *cmd;
5150 robj **argv = NULL;
5151 int argc = 0, flags = 0, j;
5152 va_list ap;
5153
5154 cmd = lookupCommandByCString((char*)cmdname);
5155 if (!cmd) {
5156 serverLog(LL_WARNING,
5157 "Fatal: AOF method for module data type '%s' tried to "
5158 "emit unknown command '%s'",
5159 io->type->name, cmdname);
5160 io->error = 1;
5161 errno = EINVAL;
5162 return;
5163 }
5164
5165 /* Emit the arguments into the AOF in Redis protocol format. */
5166 va_start(ap, fmt);
5167 argv = moduleCreateArgvFromUserFormat(cmdname,fmt,&argc,&flags,ap);
5168 va_end(ap);
5169 if (argv == NULL) {
5170 serverLog(LL_WARNING,
5171 "Fatal: AOF method for module data type '%s' tried to "
5172 "call RedisModule_EmitAOF() with wrong format specifiers '%s'",
5173 io->type->name, fmt);
5174 io->error = 1;
5175 errno = EINVAL;
5176 return;
5177 }
5178
5179 /* Bulk count. */
5180 if (!io->error && rioWriteBulkCount(io->prio,'*',argc) == 0)
5181 io->error = 1;
5182
5183 /* Arguments. */
5184 for (j = 0; j < argc; j++) {
5185 if (!io->error && rioWriteBulkObject(io->prio,argv[j]) == 0)
5186 io->error = 1;
5187 decrRefCount(argv[j]);
5188 }
5189 zfree(argv);
5190 return;
5191}
5192
5193/* --------------------------------------------------------------------------
5194 * ## IO context handling

Callers

nothing calls this directly

Calls 7

lookupCommandByCStringFunction · 0.85
serverLogFunction · 0.85
rioWriteBulkCountFunction · 0.85
rioWriteBulkObjectFunction · 0.85
decrRefCountFunction · 0.85
zfreeFunction · 0.85

Tested by

no test coverage detected