| 482 | } |
| 483 | |
| 484 | void getrangeCommand(client *c) { |
| 485 | robj *o; |
| 486 | long long start, end; |
| 487 | char *str, llbuf[32]; |
| 488 | size_t strlen; |
| 489 | |
| 490 | if (getLongLongFromObjectOrReply(c,c->argv[2],&start,NULL) != C_OK) |
| 491 | return; |
| 492 | if (getLongLongFromObjectOrReply(c,c->argv[3],&end,NULL) != C_OK) |
| 493 | return; |
| 494 | if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.emptybulk)) == NULL || |
| 495 | checkType(c,o,OBJ_STRING)) return; |
| 496 | |
| 497 | if (o->encoding == OBJ_ENCODING_INT) { |
| 498 | str = llbuf; |
| 499 | strlen = ll2string(llbuf,sizeof(llbuf),(long)o->ptr); |
| 500 | } else { |
| 501 | str = o->ptr; |
| 502 | strlen = sdslen(str); |
| 503 | } |
| 504 | |
| 505 | /* Convert negative indexes */ |
| 506 | if (start < 0 && end < 0 && start > end) { |
| 507 | addReply(c,shared.emptybulk); |
| 508 | return; |
| 509 | } |
| 510 | if (start < 0) start = strlen+start; |
| 511 | if (end < 0) end = strlen+end; |
| 512 | if (start < 0) start = 0; |
| 513 | if (end < 0) end = 0; |
| 514 | if ((unsigned long long)end >= strlen) end = strlen-1; |
| 515 | |
| 516 | /* Precondition: end >= 0 && end < strlen, so the only condition where |
| 517 | * nothing can be returned is: start > end. */ |
| 518 | if (start > end || strlen == 0) { |
| 519 | addReply(c,shared.emptybulk); |
| 520 | } else { |
| 521 | addReplyBulkCBuffer(c,(char*)str+start,end-start+1); |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | void mgetCommand(client *c) { |
| 526 | int j; |
nothing calls this directly
no test coverage detected