| 325 | } |
| 326 | |
| 327 | static void readHandler(aeEventLoop *el, int fd, void *privdata, int mask) { |
| 328 | client c = (client)privdata; |
| 329 | void *reply = NULL; |
| 330 | UNUSED(el); |
| 331 | UNUSED(fd); |
| 332 | UNUSED(mask); |
| 333 | |
| 334 | /* Calculate latency only for the first read event. This means that the |
| 335 | * server already sent the reply and we need to parse it. Parsing overhead |
| 336 | * is not part of the latency, so calculate it only once, here. */ |
| 337 | if (c->latency < 0) c->latency = ustime()-(c->start); |
| 338 | |
| 339 | if (redisBufferRead(c->context) != REDIS_OK) { |
| 340 | fprintf(stderr,"Error: %s\n",c->context->errstr); |
| 341 | exit(1); |
| 342 | } else { |
| 343 | while(c->pending) { |
| 344 | if (redisGetReply(c->context,&reply) != REDIS_OK) { |
| 345 | fprintf(stderr,"Error: %s\n",c->context->errstr); |
| 346 | exit(1); |
| 347 | } |
| 348 | if (reply != NULL) { |
| 349 | if (reply == (void*)REDIS_REPLY_ERROR) { |
| 350 | fprintf(stderr,"Unexpected error reply, exiting...\n"); |
| 351 | exit(1); |
| 352 | } |
| 353 | redisReply *r = (redisReply*)reply; |
| 354 | int is_err = (r->type == REDIS_REPLY_ERROR); |
| 355 | |
| 356 | if (is_err && config.showerrors) { |
| 357 | /* TODO: static lasterr_time not thread-safe */ |
| 358 | static time_t lasterr_time = 0; |
| 359 | time_t now = time(NULL); |
| 360 | if (lasterr_time != now) { |
| 361 | lasterr_time = now; |
| 362 | if (c->cluster_node) { |
| 363 | printf("Error from server %s:%d: %s\n", |
| 364 | c->cluster_node->ip, |
| 365 | c->cluster_node->port, |
| 366 | r->str); |
| 367 | } else printf("Error from server: %s\n", r->str); |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | freeReplyObject(reply); |
| 372 | /* This is an OK for prefix commands such as auth and select.*/ |
| 373 | if (c->prefix_pending > 0) { |
| 374 | c->prefix_pending--; |
| 375 | c->pending--; |
| 376 | /* Discard prefix commands on first response.*/ |
| 377 | if (c->prefixlen > 0) { |
| 378 | size_t j; |
| 379 | sdsrange(c->obuf, c->prefixlen, -1); |
| 380 | /* We also need to fix the pointers to the strings |
| 381 | * we need to randomize. */ |
| 382 | for (j = 0; j < c->randlen; j++) |
| 383 | c->randptr[j] -= c->prefixlen; |
| 384 | c->prefixlen = 0; |
nothing calls this directly
no test coverage detected