From b6b72250ca1dbbe95c1302cd35f4a3f1472e8483 Mon Sep 17 00:00:00 2001 From: Yue Li <61070669+theyueli@users.noreply.github.com> Date: Wed, 30 Aug 2023 03:55:38 -0700 Subject: [PATCH] fix(zset): correct the wrong calculation of range.maxex (#1759) fixes #836: correct the wrong calculation of range.maxex. --- .clang-format | 2 +- src/server/zset_family.cc | 2 +- src/server/zset_family_test.cc | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.clang-format b/.clang-format index bf80c117f..7303fd161 100644 --- a/.clang-format +++ b/.clang-format @@ -9,7 +9,7 @@ AllowShortLoopsOnASingleLine: false AllowShortFunctionsOnASingleLine: false AllowShortIfStatementsOnASingleLine: false AlwaysBreakTemplateDeclarations: false -ConstructorInitializerAllOnOneLineOrOnePerLine: false +PackConstructorInitializers: NextLine DerivePointerAlignment: false PointerAlignment: Left BasedOnStyle: Google diff --git a/src/server/zset_family.cc b/src/server/zset_family.cc index 1c2cf1b81..e3729af89 100644 --- a/src/server/zset_family.cc +++ b/src/server/zset_family.cc @@ -84,7 +84,7 @@ zlexrangespec GetLexRange(bool reverse, const ZSetFamily::LexInterval& li) { range.min = GetLexStr(interval.first); range.max = GetLexStr(interval.second); range.minex = (interval.first.type == ZSetFamily::LexBound::OPEN); - range.maxex = (li.second.type == ZSetFamily::LexBound::OPEN); + range.maxex = (interval.second.type == ZSetFamily::LexBound::OPEN); return range; } diff --git a/src/server/zset_family_test.cc b/src/server/zset_family_test.cc index ba6418f54..1987a3dd5 100644 --- a/src/server/zset_family_test.cc +++ b/src/server/zset_family_test.cc @@ -183,6 +183,11 @@ TEST_F(ZSetFamilyTest, ZRevRangeByLex) { resp = Run({"zrevrangebylex", "key", "+", "[a"}); ASSERT_THAT(resp, ArgType(RespExpr::ARRAY)); ASSERT_THAT(resp.GetVec(), ElementsAre("foo", "elephant", "down", "cool", "bar", "alpha")); + + Run({"zadd", "myzset", "0", "a", "0", "b", "0", "c", "0", "d", "0", "e", "0", "f", "0", "g"}); + resp = Run({"zrevrangebylex", "myzset", "(c", "-"}); + ASSERT_THAT(resp, ArgType(RespExpr::ARRAY)); + EXPECT_THAT(resp.GetVec(), ElementsAre("b", "a")); } TEST_F(ZSetFamilyTest, ZRange) {