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

Function sendCommand

src/replication.cpp:3117–3145  ·  view source on GitHub ↗

Compose a multi-bulk command and send it to the connection. * Used to send AUTH and REPLCONF commands to the master before starting the * replication. * * Takes a list of char* arguments, terminated by a NULL argument. * * The command returns an sds string representing the result of the * operation. On error the first byte is a "-". */

Source from the content-addressed store, hash-verified

3115 * operation. On error the first byte is a "-".
3116 */
3117char *sendCommand(connection *conn, ...) {
3118 va_list ap;
3119 sds cmd = sdsempty();
3120 sds cmdargs = sdsempty();
3121 size_t argslen = 0;
3122 char *arg;
3123
3124 /* Create the command to send to the master, we use redis binary
3125 * protocol to make sure correct arguments are sent. This function
3126 * is not safe for all binary data. */
3127 va_start(ap,conn);
3128 while(1) {
3129 arg = va_arg(ap, char*);
3130 if (arg == NULL) break;
3131 cmdargs = sdscatprintf(cmdargs,"$%zu\r\n%s\r\n",strlen(arg),arg);
3132 argslen++;
3133 }
3134
3135 cmd = sdscatprintf(cmd,"*%zu\r\n",argslen);
3136 cmd = sdscatsds(cmd,cmdargs);
3137 sdsfree(cmdargs);
3138
3139 va_end(ap);
3140 char* err = sendCommandRaw(conn, cmd);
3141 sdsfree(cmd);
3142 if(err)
3143 return err;
3144 return NULL;
3145}
3146
3147/* Compose a multi-bulk command and send it to the connection.
3148 * Used to send AUTH and REPLCONF commands to the master before starting the

Callers 2

syncWithMasterFunction · 0.85

Calls 5

sdsemptyFunction · 0.85
sdscatprintfFunction · 0.85
sdscatsdsFunction · 0.85
sdsfreeFunction · 0.85
sendCommandRawFunction · 0.85

Tested by

no test coverage detected