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
| 1870 | * The command returns REDISMODULE_ERR if the format specifiers are invalid |
| 1871 | * or the command name does not belong to a known command. */ |
| 1872 | int RM_Replicate(RedisModuleCtx *ctx, const char *cmdname, const char *fmt, ...) { |
| 1873 | struct redisCommand *cmd; |
| 1874 | robj **argv = NULL; |
| 1875 | int argc = 0, flags = 0, j; |
| 1876 | va_list ap; |
| 1877 | |
| 1878 | cmd = lookupCommandByCString((char*)cmdname); |
| 1879 | if (!cmd) return REDISMODULE_ERR; |
| 1880 | |
| 1881 | /* Create the client and dispatch the command. */ |
| 1882 | va_start(ap, fmt); |
| 1883 | argv = moduleCreateArgvFromUserFormat(cmdname,fmt,&argc,&flags,ap); |
| 1884 | va_end(ap); |
| 1885 | if (argv == NULL) return REDISMODULE_ERR; |
| 1886 | |
| 1887 | /* Select the propagation target. Usually is AOF + replicas, however |
| 1888 | * the caller can exclude one or the other using the "A" or "R" |
| 1889 | * modifiers. */ |
| 1890 | int target = 0; |
| 1891 | if (!(flags & REDISMODULE_ARGV_NO_AOF)) target |= PROPAGATE_AOF; |
| 1892 | if (!(flags & REDISMODULE_ARGV_NO_REPLICAS)) target |= PROPAGATE_REPL; |
| 1893 | |
| 1894 | /* Replicate! When we are in a threaded context, we want to just insert |
| 1895 | * the replicated command ASAP, since it is not clear when the context |
| 1896 | * will stop being used, so accumulating stuff does not make much sense, |
| 1897 | * nor we could easily use the alsoPropagate() API from threads. */ |
| 1898 | if (ctx->flags & REDISMODULE_CTX_THREAD_SAFE) { |
| 1899 | propagate(cmd,ctx->client->db->id,argv,argc,target); |
| 1900 | } else { |
| 1901 | moduleReplicateMultiIfNeeded(ctx); |
| 1902 | alsoPropagate(cmd,ctx->client->db->id,argv,argc,target); |
| 1903 | } |
| 1904 | |
| 1905 | /* Release the argv. */ |
| 1906 | for (j = 0; j < argc; j++) decrRefCount(argv[j]); |
| 1907 | zfree(argv); |
| 1908 | g_pserver->dirty++; |
| 1909 | return REDISMODULE_OK; |
| 1910 | } |
| 1911 | |
| 1912 | /* This function will replicate the command exactly as it was invoked |
| 1913 | * by the client. Note that this function will not wrap the command into |
nothing calls this directly
no test coverage detected