MCPcopy Create free account
hub / github.com/F-Stack/f-stack / zlexcountCommand

Function zlexcountCommand

app/redis-6.2.6/src/t_zset.c:3353–3430  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3351}
3352
3353void zlexcountCommand(client *c) {
3354 robj *key = c->argv[1];
3355 robj *zobj;
3356 zlexrangespec range;
3357 unsigned long count = 0;
3358
3359 /* Parse the range arguments */
3360 if (zslParseLexRange(c->argv[2],c->argv[3],&range) != C_OK) {
3361 addReplyError(c,"min or max not valid string range item");
3362 return;
3363 }
3364
3365 /* Lookup the sorted set */
3366 if ((zobj = lookupKeyReadOrReply(c, key, shared.czero)) == NULL ||
3367 checkType(c, zobj, OBJ_ZSET))
3368 {
3369 zslFreeLexRange(&range);
3370 return;
3371 }
3372
3373 if (zobj->encoding == OBJ_ENCODING_ZIPLIST) {
3374 unsigned char *zl = zobj->ptr;
3375 unsigned char *eptr, *sptr;
3376
3377 /* Use the first element in range as the starting point */
3378 eptr = zzlFirstInLexRange(zl,&range);
3379
3380 /* No "first" element */
3381 if (eptr == NULL) {
3382 zslFreeLexRange(&range);
3383 addReply(c, shared.czero);
3384 return;
3385 }
3386
3387 /* First element is in range */
3388 sptr = ziplistNext(zl,eptr);
3389 serverAssertWithInfo(c,zobj,zzlLexValueLteMax(eptr,&range));
3390
3391 /* Iterate over elements in range */
3392 while (eptr) {
3393 /* Abort when the node is no longer in range. */
3394 if (!zzlLexValueLteMax(eptr,&range)) {
3395 break;
3396 } else {
3397 count++;
3398 zzlNext(zl,&eptr,&sptr);
3399 }
3400 }
3401 } else if (zobj->encoding == OBJ_ENCODING_SKIPLIST) {
3402 zset *zs = zobj->ptr;
3403 zskiplist *zsl = zs->zsl;
3404 zskiplistNode *zn;
3405 unsigned long rank;
3406
3407 /* Find first element in range */
3408 zn = zslFirstInLexRange(zsl, &range);
3409
3410 /* Use rank of first element, if any, to determine preliminary count */

Callers

nothing calls this directly

Calls 14

zslParseLexRangeFunction · 0.85
addReplyErrorFunction · 0.85
lookupKeyReadOrReplyFunction · 0.85
checkTypeFunction · 0.85
zslFreeLexRangeFunction · 0.85
zzlFirstInLexRangeFunction · 0.85
addReplyFunction · 0.85
ziplistNextFunction · 0.85
zzlLexValueLteMaxFunction · 0.85
zzlNextFunction · 0.85
zslFirstInLexRangeFunction · 0.85
zslGetRankFunction · 0.85

Tested by

no test coverage detected