| 1292 | } |
| 1293 | |
| 1294 | static int cliReadReply(int output_raw_strings) { |
| 1295 | void *_reply; |
| 1296 | redisReply *reply; |
| 1297 | sds out = NULL; |
| 1298 | int output = 1; |
| 1299 | |
| 1300 | if (redisGetReply(context,&_reply) != REDIS_OK) { |
| 1301 | if (config.shutdown) { |
| 1302 | redisFree(context); |
| 1303 | context = NULL; |
| 1304 | return REDIS_OK; |
| 1305 | } |
| 1306 | if (config.interactive) { |
| 1307 | /* Filter cases where we should reconnect */ |
| 1308 | if (context->err == REDIS_ERR_IO && |
| 1309 | (errno == ECONNRESET || errno == EPIPE)) |
| 1310 | return REDIS_ERR; |
| 1311 | if (context->err == REDIS_ERR_EOF) |
| 1312 | return REDIS_ERR; |
| 1313 | } |
| 1314 | cliPrintContextError(); |
| 1315 | exit(1); |
| 1316 | return REDIS_ERR; /* avoid compiler warning */ |
| 1317 | } |
| 1318 | |
| 1319 | reply = (redisReply*)_reply; |
| 1320 | |
| 1321 | config.last_cmd_type = reply->type; |
| 1322 | |
| 1323 | /* Check if we need to connect to a different node and reissue the |
| 1324 | * request. */ |
| 1325 | if (config.cluster_mode && reply->type == REDIS_REPLY_ERROR && |
| 1326 | (!strncmp(reply->str,"MOVED ",6) || !strncmp(reply->str,"ASK ",4))) |
| 1327 | { |
| 1328 | char *p = reply->str, *s; |
| 1329 | int slot; |
| 1330 | |
| 1331 | output = 0; |
| 1332 | /* Comments show the position of the pointer as: |
| 1333 | * |
| 1334 | * [S] for pointer 's' |
| 1335 | * [P] for pointer 'p' |
| 1336 | */ |
| 1337 | s = strchr(p,' '); /* MOVED[S]3999 127.0.0.1:6381 */ |
| 1338 | p = strchr(s+1,' '); /* MOVED[S]3999[P]127.0.0.1:6381 */ |
| 1339 | *p = '\0'; |
| 1340 | slot = atoi(s+1); |
| 1341 | s = strrchr(p+1,':'); /* MOVED 3999[P]127.0.0.1[S]6381 */ |
| 1342 | *s = '\0'; |
| 1343 | sdsfree(config.hostip); |
| 1344 | config.hostip = sdsnew(p+1); |
| 1345 | config.hostport = atoi(s+1); |
| 1346 | if (config.interactive) |
| 1347 | printf("-> Redirected to slot [%d] located at %s:%d\n", |
| 1348 | slot, config.hostip, config.hostport); |
| 1349 | config.cluster_reissue_command = 1; |
| 1350 | if (!strncmp(reply->str,"ASK ",4)) { |
| 1351 | config.cluster_send_asking = 1; |
no test coverage detected