Helper function to replicate MULTI the first time we replicate something * in the context of a command execution. EXEC will be handled by the * RedisModuleCommandDispatcher() function. */
| 1811 | * in the context of a command execution. EXEC will be handled by the |
| 1812 | * RedisModuleCommandDispatcher() function. */ |
| 1813 | void moduleReplicateMultiIfNeeded(RedisModuleCtx *ctx) { |
| 1814 | /* Skip this if client explicitly wrap the command with MULTI, or if |
| 1815 | * the module command was called by a script. */ |
| 1816 | if (serverTL->in_eval || serverTL->in_exec) return; |
| 1817 | /* If we already emitted MULTI return ASAP. */ |
| 1818 | if (serverTL->propagate_in_transaction) return; |
| 1819 | /* If this is a thread safe context, we do not want to wrap commands |
| 1820 | * executed into MULTI/EXEC, they are executed as single commands |
| 1821 | * from an external client in essence. */ |
| 1822 | if (ctx->flags & REDISMODULE_CTX_THREAD_SAFE) return; |
| 1823 | /* If this is a callback context, and not a module command execution |
| 1824 | * context, we have to setup the op array for the "also propagate" API |
| 1825 | * so that RM_Replicate() will work. */ |
| 1826 | if (!(ctx->flags & REDISMODULE_CTX_MODULE_COMMAND_CALL)) { |
| 1827 | serverAssert(ctx->saved_oparray.ops == NULL); |
| 1828 | ctx->saved_oparray = g_pserver->also_propagate; |
| 1829 | redisOpArrayInit(&g_pserver->also_propagate); |
| 1830 | } |
| 1831 | execCommandPropagateMulti(ctx->client->db->id); |
| 1832 | ctx->flags |= REDISMODULE_CTX_MULTI_EMITTED; |
| 1833 | } |
| 1834 | |
| 1835 | /* Replicate the specified command and arguments to slaves and AOF, as effect |
| 1836 | * of execution of the calling command implementation. |
no test coverage detected