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