fix(zset): Make count optional for ZPOP{MIN,MAX} (#821)

fix(zset): Make count optional for zpop{min,max}

The commands should allow count to be optional and
default to 1 as per the official redis command documentation.

Additionally update command flags to write + fast

Signed-off-by: Ali-Akber Saifee <ali@indydevs.org>
This commit is contained in:
Ali-Akber Saifee 2023-02-19 11:19:45 -08:00 committed by GitHub
parent 4ef06e759a
commit 914dd23cdb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 13 deletions

View file

@ -416,30 +416,36 @@ TEST_F(ZSetFamilyTest, ZAddBug148) {
}
TEST_F(ZSetFamilyTest, ZPopMin) {
auto resp = Run({"zadd", "key", "1", "a", "2", "b", "3", "c", "4", "d", "5", "e"});
EXPECT_THAT(resp, IntArg(5));
auto resp = Run({"zadd", "key", "1", "a", "2", "b", "3", "c", "4", "d", "5", "e", "6", "f"});
EXPECT_THAT(resp, IntArg(6));
resp = Run({"zpopmin", "key"});
ASSERT_THAT(resp, "a");
resp = Run({"zpopmin", "key", "2"});
ASSERT_THAT(resp, ArrLen(2));
EXPECT_THAT(resp.GetVec(), ElementsAre("a", "b"));
EXPECT_THAT(resp.GetVec(), ElementsAre("b", "c"));
resp = Run({"zpopmin", "key", "-1"});
ASSERT_THAT(resp, ErrArg("value is out of range, must be positive"));
resp = Run({"zpopmin", "key", "1"});
ASSERT_THAT(resp, "c");
ASSERT_THAT(resp, "d");
resp = Run({"zpopmin", "key", "3"});
ASSERT_THAT(resp, ArrLen(2));
EXPECT_THAT(resp.GetVec(), ElementsAre("d", "e"));
EXPECT_THAT(resp.GetVec(), ElementsAre("e", "f"));
resp = Run({"zpopmin", "key", "1"});
ASSERT_THAT(resp, ArrLen(0));
}
TEST_F(ZSetFamilyTest, ZPopMax) {
auto resp = Run({"zadd", "key", "1", "a", "2", "b", "3", "c", "4", "d", "5", "e"});
EXPECT_THAT(resp, IntArg(5));
auto resp = Run({"zadd", "key", "1", "a", "2", "b", "3", "c", "4", "d", "5", "e", "6", "f"});
EXPECT_THAT(resp, IntArg(6));
resp = Run({"zpopmax", "key"});
ASSERT_THAT(resp, "f");
resp = Run({"zpopmax", "key", "2"});
ASSERT_THAT(resp, ArrLen(2));