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

Function moduleHandlePropagationAfterCommandCallback

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

Helper function for when a command callback is called, in order to handle * details needed to correctly replicate commands. */

Source from the content-addressed store, hash-verified

623/* Helper function for when a command callback is called, in order to handle
624 * details needed to correctly replicate commands. */
625void moduleHandlePropagationAfterCommandCallback(RedisModuleCtx *ctx) {
626 client *c = ctx->client;
627
628 /* We don't need to do anything here if the context was never used
629 * in order to propagate commands. */
630 if (!(ctx->flags & REDISMODULE_CTX_MULTI_EMITTED)) return;
631
632 /* We don't need to do anything here if the server isn't inside
633 * a transaction. */
634 if (!server.propagate_in_transaction) return;
635
636 /* If this command is executed from with Lua or MULTI/EXEC we do not
637 * need to propagate EXEC */
638 if (server.in_eval || server.in_exec) return;
639
640 /* Handle the replication of the final EXEC, since whatever a command
641 * emits is always wrapped around MULTI/EXEC. */
642 alsoPropagate(server.execCommand,c->db->id,&shared.exec,1,
643 PROPAGATE_AOF|PROPAGATE_REPL);
644 afterPropagateExec();
645
646 /* If this is not a module command context (but is instead a simple
647 * callback context), we have to handle directly the "also propagate"
648 * array and emit it. In a module command call this will be handled
649 * directly by call(). */
650 if (!(ctx->flags & REDISMODULE_CTX_MODULE_COMMAND_CALL) &&
651 server.also_propagate.numops)
652 {
653 for (int j = 0; j < server.also_propagate.numops; j++) {
654 redisOp *rop = &server.also_propagate.ops[j];
655 int target = rop->target;
656 if (target)
657 propagate(rop->cmd,rop->dbid,rop->argv,rop->argc,target);
658 }
659 redisOpArrayFree(&server.also_propagate);
660 /* Restore the previous oparray in case of nexted use of the API. */
661 server.also_propagate = ctx->saved_oparray;
662 /* We're done with saved_oparray, let's invalidate it. */
663 redisOpArrayInit(&ctx->saved_oparray);
664 }
665}
666
667/* Free the context after the user function was called. */
668void moduleFreeContext(RedisModuleCtx *ctx) {

Callers 1

moduleFreeContextFunction · 0.85

Calls 5

alsoPropagateFunction · 0.85
afterPropagateExecFunction · 0.85
propagateFunction · 0.85
redisOpArrayFreeFunction · 0.85
redisOpArrayInitFunction · 0.85

Tested by

no test coverage detected