Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
470c2838
Commit
470c2838
authored
Nov 08, 2018
by
antirez
Browse files
RESP3: Use new deferred len API in t_zset.c.
parent
a577230a
Changes
1
Show whitespace changes
Inline
Side-by-side
src/t_zset.c
View file @
470c2838
...
@@ -2446,7 +2446,7 @@ void zrangeGenericCommand(client *c, int reverse) {
...
@@ -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 */
addReply
MultiBulkLen(c, withscores ? (rangelen*2) :
rangelen);
addReply
ArrayLen(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) {
...
@@ -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) {
...
@@ -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) {
...
@@ -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 = addDeferred
MultiBulkLength
(c);
replylen = add
Reply
Deferred
Len
(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) {
...
@@ -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) {
...
@@ -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 = addDeferred
MultiBulkLength
(c);
replylen = add
Reply
Deferred
Len
(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) {
...
@@ -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) {
...
@@ -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) {
...
@@ -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 = addDeferred
MultiBulkLength
(c);
replylen = add
Reply
Deferred
Len
(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) {
...
@@ -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 = addDeferred
MultiBulkLength
(c);
replylen = add
Reply
Deferred
Len
(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) {
...
@@ -3048,7 +3041,7 @@ void genericZrangebylexCommand(client *c, int reverse) {
}
}
zslFreeLexRange(&range);
zslFreeLexRange(&range);
setDeferred
MultiBulkLength
(c, replylen, rangelen);
setDeferred
ArrayLen
(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
...
@@ -3160,7 +3153,7 @@ void genericZpopCommand(client *c, robj **keyv, int keyc, int where, int emitkey
return;
return;
}
}
void *arraylen_ptr = addDeferred
MultiBulkLength
(c);
void *arraylen_ptr = add
Reply
Deferred
Len
(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
...
@@ -3227,7 +3220,7 @@ void genericZpopCommand(client *c, robj **keyv, int keyc, int where, int emitkey
}
}
} while(--count);
} while(--count);
setDeferred
MultiBulkLength
(c,arraylen_ptr,arraylen + (emitkey != 0));
setDeferred
ArrayLen
(c,arraylen_ptr,arraylen + (emitkey != 0));
}
}
/* ZPOPMIN key [<count>] */
/* ZPOPMIN key [<count>] */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment