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

Function cliReadReply

src/redis-cli.c:1101–1177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1099}
1100
1101static int cliReadReply(int output_raw_strings) {
1102 void *_reply;
1103 redisReply *reply;
1104 sds out = NULL;
1105 int output = 1;
1106
1107 if (redisGetReply(context,&_reply) != REDIS_OK) {
1108 if (config.shutdown) {
1109 redisFree(context);
1110 context = NULL;
1111 return REDIS_OK;
1112 }
1113 if (config.interactive) {
1114 /* Filter cases where we should reconnect */
1115 if (context->err == REDIS_ERR_IO &&
1116 (errno == ECONNRESET || errno == EPIPE))
1117 return REDIS_ERR;
1118 if (context->err == REDIS_ERR_EOF)
1119 return REDIS_ERR;
1120 }
1121 cliPrintContextError();
1122 exit(1);
1123 return REDIS_ERR; /* avoid compiler warning */
1124 }
1125
1126 reply = (redisReply*)_reply;
1127
1128 config.last_cmd_type = reply->type;
1129
1130 /* Check if we need to connect to a different node and reissue the
1131 * request. */
1132 if (config.cluster_mode && reply->type == REDIS_REPLY_ERROR &&
1133 (!strncmp(reply->str,"MOVED ",6) || !strncmp(reply->str,"ASK ",4)))
1134 {
1135 char *p = reply->str, *s;
1136 int slot;
1137
1138 output = 0;
1139 /* Comments show the position of the pointer as:
1140 *
1141 * [S] for pointer 's'
1142 * [P] for pointer 'p'
1143 */
1144 s = strchr(p,' '); /* MOVED[S]3999 127.0.0.1:6381 */
1145 p = strchr(s+1,' '); /* MOVED[S]3999[P]127.0.0.1:6381 */
1146 *p = '\0';
1147 slot = atoi(s+1);
1148 s = strrchr(p+1,':'); /* MOVED 3999[P]127.0.0.1[S]6381 */
1149 *s = '\0';
1150 sdsfree(config.hostip);
1151 config.hostip = sdsnew(p+1);
1152 config.hostport = atoi(s+1);
1153 if (config.interactive)
1154 printf("-> Redirected to slot [%d] located at %s:%d\n",
1155 slot, config.hostip, config.hostport);
1156 config.cluster_reissue_command = 1;
1157 if (!strncmp(reply->str,"ASK ",4)) {
1158 config.cluster_send_asking = 1;

Callers 4

cliSendCommandFunction · 0.85
replFunction · 0.85
evalModeFunction · 0.85
slaveModeFunction · 0.85

Calls 9

redisGetReplyFunction · 0.85
redisFreeFunction · 0.85
cliPrintContextErrorFunction · 0.85
sdsfreeFunction · 0.85
sdsnewFunction · 0.85
cliRefreshPromptFunction · 0.85
cliFormatReplyFunction · 0.85
sdslenFunction · 0.85
freeReplyObjectFunction · 0.85

Tested by

no test coverage detected