diff --git a/src/t_zset.c b/src/t_zset.c index 84a61ca4..9246c37c 100644 --- a/src/t_zset.c +++ b/src/t_zset.c @@ -2446,7 +2446,7 @@ void zrangeGenericCommand(client *c, int reverse) { rangelen = (end-start)+1; /* Return the result in form of a multi-bulk reply */ - addReplyMultiBulkLen(c, withscores ? (rangelen*2) : rangelen); + addReplyArrayLen(c, rangelen); if (zobj->encoding == OBJ_ENCODING_ZIPLIST) { unsigned char *zl = zobj->ptr; @@ -2466,13 +2466,13 @@ void zrangeGenericCommand(client *c, int reverse) { while (rangelen--) { serverAssertWithInfo(c,zobj,eptr != NULL && sptr != NULL); serverAssertWithInfo(c,zobj,ziplistGet(eptr,&vstr,&vlen,&vlong)); + + if (withscores) addReplyArrayLen(c,2); if (vstr == NULL) addReplyBulkLongLong(c,vlong); else addReplyBulkCBuffer(c,vstr,vlen); - - if (withscores) - addReplyDouble(c,zzlGetScore(sptr)); + if (withscores) addReplyDouble(c,zzlGetScore(sptr)); if (reverse) zzlPrev(zl,&eptr,&sptr); @@ -2500,9 +2500,9 @@ void zrangeGenericCommand(client *c, int reverse) { while(rangelen--) { serverAssertWithInfo(c,zobj,ln != NULL); ele = ln->ele; + if (withscores) addReplyArrayLen(c,2); addReplyBulkCBuffer(c,ele,sdslen(ele)); - if (withscores) - addReplyDouble(c,ln->score); + if (withscores) addReplyDouble(c,ln->score); ln = reverse ? ln->backward : ln->level[0].forward; } } else { @@ -2601,7 +2601,7 @@ void genericZrangebyscoreCommand(client *c, int reverse) { /* We don't know in advance how many matching elements there are in the * list, so we push this object that will represent the multi-bulk * length in the output buffer, and will "fix" it later */ - replylen = addDeferredMultiBulkLength(c); + replylen = addReplyDeferredLen(c); /* If there is an offset, just traverse the number of elements without * checking the score because that is done in the next loop. */ @@ -2623,19 +2623,18 @@ void genericZrangebyscoreCommand(client *c, int reverse) { if (!zslValueLteMax(score,&range)) break; } - /* We know the element exists, so ziplistGet should always succeed */ + /* We know the element exists, so ziplistGet should always + * succeed */ serverAssertWithInfo(c,zobj,ziplistGet(eptr,&vstr,&vlen,&vlong)); rangelen++; + if (withscores) addReplyArrayLen(c,2); if (vstr == NULL) { addReplyBulkLongLong(c,vlong); } else { addReplyBulkCBuffer(c,vstr,vlen); } - - if (withscores) { - addReplyDouble(c,score); - } + if (withscores) addReplyDouble(c,score); /* Move to next node */ if (reverse) { @@ -2665,7 +2664,7 @@ void genericZrangebyscoreCommand(client *c, int reverse) { /* We don't know in advance how many matching elements there are in the * list, so we push this object that will represent the multi-bulk * length in the output buffer, and will "fix" it later */ - replylen = addDeferredMultiBulkLength(c); + replylen = addReplyDeferredLen(c); /* If there is an offset, just traverse the number of elements without * checking the score because that is done in the next loop. */ @@ -2686,11 +2685,9 @@ void genericZrangebyscoreCommand(client *c, int reverse) { } rangelen++; + if (withscores) addReplyArrayLen(c,2); addReplyBulkCBuffer(c,ln->ele,sdslen(ln->ele)); - - if (withscores) { - addReplyDouble(c,ln->score); - } + if (withscores) addReplyDouble(c,ln->score); /* Move to next node */ if (reverse) { @@ -2703,11 +2700,7 @@ void genericZrangebyscoreCommand(client *c, int reverse) { serverPanic("Unknown sorted set encoding"); } - if (withscores) { - rangelen *= 2; - } - - setDeferredMultiBulkLength(c, replylen, rangelen); + setDeferredArrayLen(c, replylen, rangelen); } void zrangebyscoreCommand(client *c) { @@ -2953,7 +2946,7 @@ void genericZrangebylexCommand(client *c, int reverse) { /* We don't know in advance how many matching elements there are in the * list, so we push this object that will represent the multi-bulk * length in the output buffer, and will "fix" it later */ - replylen = addDeferredMultiBulkLength(c); + replylen = addReplyDeferredLen(c); /* If there is an offset, just traverse the number of elements without * checking the score because that is done in the next loop. */ @@ -3013,7 +3006,7 @@ void genericZrangebylexCommand(client *c, int reverse) { /* We don't know in advance how many matching elements there are in the * list, so we push this object that will represent the multi-bulk * length in the output buffer, and will "fix" it later */ - replylen = addDeferredMultiBulkLength(c); + replylen = addReplyDeferredLen(c); /* If there is an offset, just traverse the number of elements without * checking the score because that is done in the next loop. */ @@ -3048,7 +3041,7 @@ void genericZrangebylexCommand(client *c, int reverse) { } zslFreeLexRange(&range); - setDeferredMultiBulkLength(c, replylen, rangelen); + setDeferredArrayLen(c, replylen, rangelen); } void zrangebylexCommand(client *c) { @@ -3160,7 +3153,7 @@ void genericZpopCommand(client *c, robj **keyv, int keyc, int where, int emitkey return; } - void *arraylen_ptr = addDeferredMultiBulkLength(c); + void *arraylen_ptr = addReplyDeferredLen(c); long arraylen = 0; /* We emit the key only for the blocking variant. */ @@ -3227,7 +3220,7 @@ void genericZpopCommand(client *c, robj **keyv, int keyc, int where, int emitkey } } while(--count); - setDeferredMultiBulkLength(c,arraylen_ptr,arraylen + (emitkey != 0)); + setDeferredArrayLen(c,arraylen_ptr,arraylen + (emitkey != 0)); } /* ZPOPMIN key [] */