Skip to content

Commit

Permalink
feat(server): zrange family command support INF as case insensitive d…
Browse files Browse the repository at this point in the history
…ragonflydb#326

Signed-off-by: Boaz Sade <[email protected]>
  • Loading branch information
boazsade committed Sep 29, 2022
1 parent 2686b93 commit 6393ea0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/server/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "server/common.h"

#include <absl/strings/charconv.h>
#include <absl/strings/match.h>
#include <absl/strings/str_cat.h>
#include <mimalloc.h>

Expand Down Expand Up @@ -168,9 +169,9 @@ bool ParseDouble(string_view src, double* value) {
if (src.empty())
return false;

if (src == "-inf") {
if (absl::EqualsIgnoreCase(src, "-inf")) {
*value = -HUGE_VAL;
} else if (src == "+inf") {
} else if (absl::EqualsIgnoreCase(src, "+inf")) {
*value = HUGE_VAL;
} else {
absl::from_chars_result result = absl::from_chars(src.data(), src.end(), *value);
Expand Down
10 changes: 10 additions & 0 deletions src/server/zset_family_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ TEST_F(ZSetFamilyTest, ZRevRange) {
resp = Run({"zrevrange", "key", "1", "2", "withscores"});
ASSERT_THAT(resp, ArrLen(4));
EXPECT_THAT(resp.GetVec(), ElementsAre("b", "1", "a", "-inf"));

// Make sure that when using with upper case it works as well (see
// https://github.com/dragonflydb/dragonfly/issues/326)
resp = Run({"zrevrangebyscore", "key", "2", "-INF"});
ASSERT_THAT(resp, ArrLen(3));
EXPECT_THAT(resp.GetVec(), ElementsAre("c", "b", "a"));

resp = Run({"zrevrangebyscore", "key", "2", "-INF", "withscores"});
ASSERT_THAT(resp, ArrLen(6));
EXPECT_THAT(resp.GetVec(), ElementsAre("c", "2", "b", "1", "a", "-inf"));
}

TEST_F(ZSetFamilyTest, ZScan) {
Expand Down

0 comments on commit 6393ea0

Please sign in to comment.