mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 18:35:46 +02:00
fix: ZMSCORE return value if key does not exist (#4697)
* tests were added * bug has been fixed * formatting was fixed * review comments have been fixed * outdated comment has been removed
This commit is contained in:
parent
2644d69239
commit
28e1a48781
2 changed files with 19 additions and 0 deletions
|
@ -1360,6 +1360,13 @@ OpResult<unsigned> OpRem(const OpArgs& op_args, string_view key, facade::ArgRang
|
|||
OpResult<MScoreResponse> OpMScore(const OpArgs& op_args, string_view key,
|
||||
facade::ArgRange members) {
|
||||
auto res_it = op_args.GetDbSlice().FindReadOnly(op_args.db_cntx, key, OBJ_ZSET);
|
||||
|
||||
if (res_it.status() == OpStatus::KEY_NOTFOUND) {
|
||||
// If the key doesn't exist return an array of NIL values
|
||||
MScoreResponse result(members.Size(), std::nullopt);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (!res_it)
|
||||
return res_it.status();
|
||||
|
||||
|
|
|
@ -287,6 +287,18 @@ TEST_F(ZSetFamilyTest, ZMScore) {
|
|||
EXPECT_THAT(resp.GetVec(), ElementsAre("42", "3.14", ArgType(RespExpr::NIL)));
|
||||
}
|
||||
|
||||
// Test for ZMSCORE with member on a non-existent keys
|
||||
TEST_F(ZSetFamilyTest, ZMScoreNonExistentKeys) {
|
||||
// Case 1: Single member with non-existent key (ZMSCORE abc x)
|
||||
auto resp = Run({"zmscore", "abc", "x"});
|
||||
EXPECT_THAT(resp, ArgType(RespExpr::NIL));
|
||||
|
||||
// Case 2: Multiple members with non-existent key (ZMSCORE abc x y z)
|
||||
resp = Run({"zmscore", "abc", "x", "y", "z"});
|
||||
EXPECT_THAT(resp.GetVec(),
|
||||
ElementsAre(ArgType(RespExpr::NIL), ArgType(RespExpr::NIL), ArgType(RespExpr::NIL)));
|
||||
}
|
||||
|
||||
TEST_F(ZSetFamilyTest, ZRangeRank) {
|
||||
Run({"zadd", "x", "1.1", "a", "2.1", "b"});
|
||||
EXPECT_THAT(Run({"zrangebyscore", "x", "0", "(1.1"}), ArrLen(0));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue