You need to sign in or sign up before continuing.
Commit 99cec798 authored by Pieter Noordhuis's avatar Pieter Noordhuis
Browse files

Test for empty inner range when looking for elements in range

parent ccf96e19
...@@ -226,10 +226,12 @@ zskiplistNode *zslFirstInRange(zskiplist *zsl, zrangespec range) { ...@@ -226,10 +226,12 @@ zskiplistNode *zslFirstInRange(zskiplist *zsl, zrangespec range) {
x = x->level[i].forward; x = x->level[i].forward;
} }
/* The tail is in range, so the previous block should always return a /* This is an inner range, so the next node cannot be NULL. */
* node that is non-NULL and the last one to be out of range. */
x = x->level[0].forward; x = x->level[0].forward;
redisAssert(x != NULL && zslValueInRange(x->score,&range)); redisAssert(x != NULL);
/* Check if score <= max. */
if (!zslValueLteMax(x->score,&range)) return NULL;
return x; return x;
} }
...@@ -250,9 +252,11 @@ zskiplistNode *zslLastInRange(zskiplist *zsl, zrangespec range) { ...@@ -250,9 +252,11 @@ zskiplistNode *zslLastInRange(zskiplist *zsl, zrangespec range) {
x = x->level[i].forward; x = x->level[i].forward;
} }
/* The header is in range, so the previous block should always return a /* This is an inner range, so this node cannot be NULL. */
* node that is non-NULL and in range. */ redisAssert(x != NULL);
redisAssert(x != NULL && zslValueInRange(x->score,&range));
/* Check if score >= min. */
if (!zslValueGteMin(x->score,&range)) return NULL;
return x; return x;
} }
...@@ -531,8 +535,12 @@ unsigned char *zzlFirstInRange(unsigned char *zl, zrangespec range) { ...@@ -531,8 +535,12 @@ unsigned char *zzlFirstInRange(unsigned char *zl, zrangespec range) {
redisAssert(sptr != NULL); redisAssert(sptr != NULL);
score = zzlGetScore(sptr); score = zzlGetScore(sptr);
if (zslValueGteMin(score,&range)) if (zslValueGteMin(score,&range)) {
return eptr; /* Check if score <= max. */
if (zslValueLteMax(score,&range))
return eptr;
return NULL;
}
/* Move to next element. */ /* Move to next element. */
eptr = ziplistNext(zl,sptr); eptr = ziplistNext(zl,sptr);
...@@ -555,8 +563,12 @@ unsigned char *zzlLastInRange(unsigned char *zl, zrangespec range) { ...@@ -555,8 +563,12 @@ unsigned char *zzlLastInRange(unsigned char *zl, zrangespec range) {
redisAssert(sptr != NULL); redisAssert(sptr != NULL);
score = zzlGetScore(sptr); score = zzlGetScore(sptr);
if (zslValueLteMax(score,&range)) if (zslValueLteMax(score,&range)) {
return eptr; /* Check if score >= min. */
if (zslValueGteMin(score,&range))
return eptr;
return NULL;
}
/* Move to previous element by moving to the score of previous element. /* Move to previous element by moving to the score of previous element.
* When this returns NULL, we know there also is no element. */ * When this returns NULL, we know there also is no element. */
......
...@@ -247,6 +247,12 @@ start_server {tags {"zset"}} { ...@@ -247,6 +247,12 @@ start_server {tags {"zset"}} {
assert_equal {} [r zrangebyscore zset (-inf (-6] assert_equal {} [r zrangebyscore zset (-inf (-6]
assert_equal {} [r zrevrangebyscore zset (+inf (6] assert_equal {} [r zrevrangebyscore zset (+inf (6]
assert_equal {} [r zrevrangebyscore zset (-6 (-inf] assert_equal {} [r zrevrangebyscore zset (-6 (-inf]
# empty inner range
assert_equal {} [r zrangebyscore zset 2.4 2.6]
assert_equal {} [r zrangebyscore zset (2.4 2.6]
assert_equal {} [r zrangebyscore zset 2.4 (2.6]
assert_equal {} [r zrangebyscore zset (2.4 (2.6]
} }
test "ZRANGEBYSCORE with WITHSCORES" { test "ZRANGEBYSCORE with WITHSCORES" {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment