Skip to content

Commit

Permalink
clang formatting issue fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MaheshMadushan committed Jan 15, 2024
1 parent 1450e88 commit ff86062
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 22 deletions.
16 changes: 4 additions & 12 deletions src/commands/cmd_zset.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,6 @@ class CommandZScan : public CommandSubkeyScanBase {
}
};


class CommandZDiff : public Commander {
public:
Status Parse(const std::vector<std::string> &args) override {
Expand Down Expand Up @@ -1406,9 +1405,9 @@ class CommandZDiff : public Commander {
}

protected:
size_t numkeys_ {0};
size_t numkeys_ = 0;
std::vector<rocksdb::Slice> keys_;
bool with_scores_ {false};
bool with_scores_ = false;
};

class CommandZDiffStore : public Commander {
Expand All @@ -1426,12 +1425,6 @@ class CommandZDiffStore : public Commander {
j++;
}

if (auto i = 2 + numkeys_; i < args.size()) {
if (util::ToLower(args[i]) == "withscores") {
with_scores_ = true;
}
}

return Commander::Parse(args);
}

Expand All @@ -1453,9 +1446,8 @@ class CommandZDiffStore : public Commander {
}

protected:
size_t numkeys_ {0};
size_t numkeys_ = 0;
std::vector<rocksdb::Slice> keys_;
bool with_scores_ {false};
};

REDIS_REGISTER_COMMANDS(MakeCmdAttr<CommandZAdd>("zadd", -4, "write", 1, 1, 1),
Expand Down Expand Up @@ -1489,7 +1481,7 @@ REDIS_REGISTER_COMMANDS(MakeCmdAttr<CommandZAdd>("zadd", -4, "write", 1, 1, 1),
MakeCmdAttr<CommandZMScore>("zmscore", -3, "read-only", 1, 1, 1),
MakeCmdAttr<CommandZScan>("zscan", -3, "read-only", 1, 1, 1),
MakeCmdAttr<CommandZUnionStore>("zunionstore", -4, "write", CommandZUnionStore::Range),
MakeCmdAttr<CommandZUnion>("zunion", -3, "read-only", CommandZUnion::Range),
MakeCmdAttr<CommandZUnion>("zunion", -3, "read-only", CommandZUnion::Range),
MakeCmdAttr<CommandZDiff>("zdiff", -3, "read-only", CommandZDiff::Range),
MakeCmdAttr<CommandZDiffStore>("zdiffstore", -3, "read-only", CommandZDiffStore::Range), )

Expand Down
9 changes: 4 additions & 5 deletions src/types/redis_zset.cc
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,6 @@ rocksdb::Status ZSet::MGet(const Slice &user_key, const std::vector<Slice> &memb
return rocksdb::Status::OK();
}


rocksdb::Status ZSet::Diff(const std::vector<Slice> &keys, MemberScores *members) {
std::vector<std::string> lock_keys;
lock_keys.reserve(keys.size());
Expand All @@ -864,14 +863,14 @@ rocksdb::Status ZSet::Diff(const std::vector<Slice> &keys, MemberScores *members
members->clear();
MemberScores source_member_scores;
RangeScoreSpec spec;
uint64_t size {0};
uint64_t size = 0;
auto s = RangeByScore(keys[0], spec, &source_member_scores, &size);
if (!s.ok()) return s;

std::map<std::string, bool> exclude_members {};
MemberScores target_member_scores {};
std::map<std::string, bool> exclude_members;
MemberScores target_member_scores;
for (size_t i = 1; i < keys.size(); i++) {
uint64_t size {0};
uint64_t size = 0;
s = RangeByScore(keys[i], spec, &target_member_scores, &size);
if (!s.ok()) return s;
for (const auto &member_score : target_member_scores) {
Expand Down
9 changes: 4 additions & 5 deletions tests/cppunit/types/zset_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -434,18 +434,17 @@ TEST_F(RedisZSetTest, Rank) {
auto s = zset_->Del(key_);
}


TEST_F(RedisZSetTest, Diff) {
uint64_t ret = 0;

std::string k1 = "key1";
std::vector<MemberScore> k1_mscores {{"a", -100.1}, {"b", -100.1}, {"c", 0}, {"d", 1.234}};
std::vector<MemberScore> k1_mscores = {{"a", -100.1}, {"b", -100.1}, {"c", 0}, {"d", 1.234}};

std::string k2 = "key2";
std::vector<MemberScore> k2_mscores {{"c", -150.1}};
std::vector<MemberScore> k2_mscores = {{"c", -150.1}};

std::string k3 = "key3";
std::vector<MemberScore> k3_mscores {{"a", -1000.1}, {"c", -100.1}, {"e", 8000.9}};
std::vector<MemberScore> k3_mscores = {{"a", -1000.1}, {"c", -100.1}, {"e", 8000.9}};

auto s = zset_->Add(k1, ZAddFlags::Default(), &k1_mscores, &ret);
EXPECT_EQ(ret, 4);
Expand All @@ -458,7 +457,7 @@ TEST_F(RedisZSetTest, Diff) {
zset_->Diff({k1, k2, k3}, &mscores);

EXPECT_EQ(2, mscores.size());
std::vector<MemberScore> expected_mscores {{"b", -100.1}, {"d", 1.234}};
std::vector<MemberScore> expected_mscores = {{"b", -100.1}, {"d", 1.234}};
int index = 0;
for (auto mscore : expected_mscores) {
EXPECT_EQ(mscore.member, mscores[index].member);
Expand Down

0 comments on commit ff86062

Please sign in to comment.