mirror of
https://github.com/fluencelabs/redis
synced 2025-03-30 22:31:03 +00:00
RESP3: Use new deferred len API in t_zset.c.
This commit is contained in:
parent
a577230a58
commit
470c28380f
47
src/t_zset.c
47
src/t_zset.c
@ -2446,7 +2446,7 @@ void zrangeGenericCommand(client *c, int reverse) {
|
|||||||
rangelen = (end-start)+1;
|
rangelen = (end-start)+1;
|
||||||
|
|
||||||
/* Return the result in form of a multi-bulk reply */
|
/* 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) {
|
if (zobj->encoding == OBJ_ENCODING_ZIPLIST) {
|
||||||
unsigned char *zl = zobj->ptr;
|
unsigned char *zl = zobj->ptr;
|
||||||
@ -2466,13 +2466,13 @@ void zrangeGenericCommand(client *c, int reverse) {
|
|||||||
while (rangelen--) {
|
while (rangelen--) {
|
||||||
serverAssertWithInfo(c,zobj,eptr != NULL && sptr != NULL);
|
serverAssertWithInfo(c,zobj,eptr != NULL && sptr != NULL);
|
||||||
serverAssertWithInfo(c,zobj,ziplistGet(eptr,&vstr,&vlen,&vlong));
|
serverAssertWithInfo(c,zobj,ziplistGet(eptr,&vstr,&vlen,&vlong));
|
||||||
|
|
||||||
|
if (withscores) addReplyArrayLen(c,2);
|
||||||
if (vstr == NULL)
|
if (vstr == NULL)
|
||||||
addReplyBulkLongLong(c,vlong);
|
addReplyBulkLongLong(c,vlong);
|
||||||
else
|
else
|
||||||
addReplyBulkCBuffer(c,vstr,vlen);
|
addReplyBulkCBuffer(c,vstr,vlen);
|
||||||
|
if (withscores) addReplyDouble(c,zzlGetScore(sptr));
|
||||||
if (withscores)
|
|
||||||
addReplyDouble(c,zzlGetScore(sptr));
|
|
||||||
|
|
||||||
if (reverse)
|
if (reverse)
|
||||||
zzlPrev(zl,&eptr,&sptr);
|
zzlPrev(zl,&eptr,&sptr);
|
||||||
@ -2500,9 +2500,9 @@ void zrangeGenericCommand(client *c, int reverse) {
|
|||||||
while(rangelen--) {
|
while(rangelen--) {
|
||||||
serverAssertWithInfo(c,zobj,ln != NULL);
|
serverAssertWithInfo(c,zobj,ln != NULL);
|
||||||
ele = ln->ele;
|
ele = ln->ele;
|
||||||
|
if (withscores) addReplyArrayLen(c,2);
|
||||||
addReplyBulkCBuffer(c,ele,sdslen(ele));
|
addReplyBulkCBuffer(c,ele,sdslen(ele));
|
||||||
if (withscores)
|
if (withscores) addReplyDouble(c,ln->score);
|
||||||
addReplyDouble(c,ln->score);
|
|
||||||
ln = reverse ? ln->backward : ln->level[0].forward;
|
ln = reverse ? ln->backward : ln->level[0].forward;
|
||||||
}
|
}
|
||||||
} else {
|
} 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
|
/* 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
|
* list, so we push this object that will represent the multi-bulk
|
||||||
* length in the output buffer, and will "fix" it later */
|
* 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
|
/* If there is an offset, just traverse the number of elements without
|
||||||
* checking the score because that is done in the next loop. */
|
* 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;
|
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));
|
serverAssertWithInfo(c,zobj,ziplistGet(eptr,&vstr,&vlen,&vlong));
|
||||||
|
|
||||||
rangelen++;
|
rangelen++;
|
||||||
|
if (withscores) addReplyArrayLen(c,2);
|
||||||
if (vstr == NULL) {
|
if (vstr == NULL) {
|
||||||
addReplyBulkLongLong(c,vlong);
|
addReplyBulkLongLong(c,vlong);
|
||||||
} else {
|
} else {
|
||||||
addReplyBulkCBuffer(c,vstr,vlen);
|
addReplyBulkCBuffer(c,vstr,vlen);
|
||||||
}
|
}
|
||||||
|
if (withscores) addReplyDouble(c,score);
|
||||||
if (withscores) {
|
|
||||||
addReplyDouble(c,score);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Move to next node */
|
/* Move to next node */
|
||||||
if (reverse) {
|
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
|
/* 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
|
* list, so we push this object that will represent the multi-bulk
|
||||||
* length in the output buffer, and will "fix" it later */
|
* 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
|
/* If there is an offset, just traverse the number of elements without
|
||||||
* checking the score because that is done in the next loop. */
|
* checking the score because that is done in the next loop. */
|
||||||
@ -2686,11 +2685,9 @@ void genericZrangebyscoreCommand(client *c, int reverse) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rangelen++;
|
rangelen++;
|
||||||
|
if (withscores) addReplyArrayLen(c,2);
|
||||||
addReplyBulkCBuffer(c,ln->ele,sdslen(ln->ele));
|
addReplyBulkCBuffer(c,ln->ele,sdslen(ln->ele));
|
||||||
|
if (withscores) addReplyDouble(c,ln->score);
|
||||||
if (withscores) {
|
|
||||||
addReplyDouble(c,ln->score);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Move to next node */
|
/* Move to next node */
|
||||||
if (reverse) {
|
if (reverse) {
|
||||||
@ -2703,11 +2700,7 @@ void genericZrangebyscoreCommand(client *c, int reverse) {
|
|||||||
serverPanic("Unknown sorted set encoding");
|
serverPanic("Unknown sorted set encoding");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (withscores) {
|
setDeferredArrayLen(c, replylen, rangelen);
|
||||||
rangelen *= 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
setDeferredMultiBulkLength(c, replylen, rangelen);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void zrangebyscoreCommand(client *c) {
|
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
|
/* 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
|
* list, so we push this object that will represent the multi-bulk
|
||||||
* length in the output buffer, and will "fix" it later */
|
* 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
|
/* If there is an offset, just traverse the number of elements without
|
||||||
* checking the score because that is done in the next loop. */
|
* 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
|
/* 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
|
* list, so we push this object that will represent the multi-bulk
|
||||||
* length in the output buffer, and will "fix" it later */
|
* 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
|
/* If there is an offset, just traverse the number of elements without
|
||||||
* checking the score because that is done in the next loop. */
|
* checking the score because that is done in the next loop. */
|
||||||
@ -3048,7 +3041,7 @@ void genericZrangebylexCommand(client *c, int reverse) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
zslFreeLexRange(&range);
|
zslFreeLexRange(&range);
|
||||||
setDeferredMultiBulkLength(c, replylen, rangelen);
|
setDeferredArrayLen(c, replylen, rangelen);
|
||||||
}
|
}
|
||||||
|
|
||||||
void zrangebylexCommand(client *c) {
|
void zrangebylexCommand(client *c) {
|
||||||
@ -3160,7 +3153,7 @@ void genericZpopCommand(client *c, robj **keyv, int keyc, int where, int emitkey
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *arraylen_ptr = addDeferredMultiBulkLength(c);
|
void *arraylen_ptr = addReplyDeferredLen(c);
|
||||||
long arraylen = 0;
|
long arraylen = 0;
|
||||||
|
|
||||||
/* We emit the key only for the blocking variant. */
|
/* 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);
|
} while(--count);
|
||||||
|
|
||||||
setDeferredMultiBulkLength(c,arraylen_ptr,arraylen + (emitkey != 0));
|
setDeferredArrayLen(c,arraylen_ptr,arraylen + (emitkey != 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ZPOPMIN key [<count>] */
|
/* ZPOPMIN key [<count>] */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user