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

Function RM_Replicate

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

Replicate the specified command and arguments to slaves and AOF, as effect * of execution of the calling command implementation. * * The replicated commands are always wrapped into the MULTI/EXEC that * contains all the commands replicated in a given module command * execution. However the commands replicated with RedisModule_Call() * are the first items, the ones replicated with RedisModule

Source from the content-addressed store, hash-verified

1800 * The command returns REDISMODULE_ERR if the format specifiers are invalid
1801 * or the command name does not belong to a known command. */
1802int RM_Replicate(RedisModuleCtx *ctx, const char *cmdname, const char *fmt, ...) {
1803 struct redisCommand *cmd;
1804 robj **argv = NULL;
1805 int argc = 0, flags = 0, j;
1806 va_list ap;
1807
1808 cmd = lookupCommandByCString((char*)cmdname);
1809 if (!cmd) return REDISMODULE_ERR;
1810
1811 /* Create the client and dispatch the command. */
1812 va_start(ap, fmt);
1813 argv = moduleCreateArgvFromUserFormat(cmdname,fmt,&argc,&flags,ap);
1814 va_end(ap);
1815 if (argv == NULL) return REDISMODULE_ERR;
1816
1817 /* Select the propagation target. Usually is AOF + replicas, however
1818 * the caller can exclude one or the other using the "A" or "R"
1819 * modifiers. */
1820 int target = 0;
1821 if (!(flags & REDISMODULE_ARGV_NO_AOF)) target |= PROPAGATE_AOF;
1822 if (!(flags & REDISMODULE_ARGV_NO_REPLICAS)) target |= PROPAGATE_REPL;
1823
1824 /* Replicate! When we are in a threaded context, we want to just insert
1825 * the replicated command ASAP, since it is not clear when the context
1826 * will stop being used, so accumulating stuff does not make much sense,
1827 * nor we could easily use the alsoPropagate() API from threads. */
1828 if (ctx->flags & REDISMODULE_CTX_THREAD_SAFE) {
1829 propagate(cmd,ctx->client->db->id,argv,argc,target);
1830 } else {
1831 moduleReplicateMultiIfNeeded(ctx);
1832 alsoPropagate(cmd,ctx->client->db->id,argv,argc,target);
1833 }
1834
1835 /* Release the argv. */
1836 for (j = 0; j < argc; j++) decrRefCount(argv[j]);
1837 zfree(argv);
1838 server.dirty++;
1839 return REDISMODULE_OK;
1840}
1841
1842/* This function will replicate the command exactly as it was invoked
1843 * by the client. Note that this function will not wrap the command into

Callers

nothing calls this directly

Calls 7

lookupCommandByCStringFunction · 0.85
propagateFunction · 0.85
alsoPropagateFunction · 0.85
decrRefCountFunction · 0.85
zfreeFunction · 0.70

Tested by

no test coverage detected