Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(server): Sort correctly in ZINTER #3566

Merged
merged 1 commit into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/server/zset_family.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2133,7 +2133,7 @@ void ZSetFamily::ZInter(CmdArgList args, ConnectionContext* cntx) {

std::sort(scored_array.begin(), scored_array.end(),
[](const std::pair<std::string, double>& a, const std::pair<std::string, double>& b) {
return a.second < b.second;
return tie(a.second, a.first) < tie(b.second, b.first);
});

auto* rb = static_cast<RedisReplyBuilder*>(cntx->reply_builder());
Expand Down
8 changes: 8 additions & 0 deletions src/server/zset_family_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,14 @@ TEST_F(ZSetFamilyTest, ZInter) {

resp = Run({"zinter", "3", "z3", "z4", "z5"});
EXPECT_THAT(resp, ArrLen(0));

// zinter output sorts keys with equal scores lexicographically
Run({"del", "z1", "z2", "z3", "z4", "z5"});
Run({"zadd", "z1", "1", "e", "1", "a", "1", "b", "1", "x"});
Run({"zadd", "z2", "1", "e", "1", "a", "1", "b", "1", "y"});
Run({"zadd", "z3", "1", "e", "1", "a", "1", "b", "1", "z"});
Run({"zadd", "z4", "1", "e", "1", "a", "1", "b", "1", "o"});
EXPECT_THAT(Run({"zinter", "4", "z1", "z2", "z3", "z4"}).GetVec(), ElementsAre("a", "b", "e"));
}

TEST_F(ZSetFamilyTest, ZInterCard) {
Expand Down
Loading