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 "-". */
| 1944 | * operation. On error the first byte is a "-". |
| 1945 | */ |
| 1946 | char *sendCommand(connection *conn, ...) { |
| 1947 | va_list ap; |
| 1948 | sds cmd = sdsempty(); |
| 1949 | sds cmdargs = sdsempty(); |
| 1950 | size_t argslen = 0; |
| 1951 | char *arg; |
| 1952 | |
| 1953 | /* Create the command to send to the master, we use redis binary |
| 1954 | * protocol to make sure correct arguments are sent. This function |
| 1955 | * is not safe for all binary data. */ |
| 1956 | va_start(ap,conn); |
| 1957 | while(1) { |
| 1958 | arg = va_arg(ap, char*); |
| 1959 | if (arg == NULL) break; |
| 1960 | cmdargs = sdscatprintf(cmdargs,"$%zu\r\n%s\r\n",strlen(arg),arg); |
| 1961 | argslen++; |
| 1962 | } |
| 1963 | |
| 1964 | cmd = sdscatprintf(cmd,"*%zu\r\n",argslen); |
| 1965 | cmd = sdscatsds(cmd,cmdargs); |
| 1966 | sdsfree(cmdargs); |
| 1967 | |
| 1968 | va_end(ap); |
| 1969 | char* err = sendCommandRaw(conn, cmd); |
| 1970 | sdsfree(cmd); |
| 1971 | if(err) |
| 1972 | return err; |
| 1973 | return NULL; |
| 1974 | } |
| 1975 | |
| 1976 | /* Compose a multi-bulk command and send it to the connection. |
| 1977 | * Used to send AUTH and REPLCONF commands to the master before starting the |
no test coverage detected