You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kvrocks.apache.org by "git-hulk (via GitHub)" <gi...@apache.org> on 2023/05/07 09:47:50 UTC
[GitHub] [incubator-kvrocks] git-hulk commented on a diff in pull request #1429: refactor: zset ranges
git-hulk commented on code in PR #1429:
URL: https://github.com/apache/incubator-kvrocks/pull/1429#discussion_r1186819646
##########
src/commands/cmd_zset.cc:
##########
@@ -356,59 +356,49 @@ class CommandZRangeGeneric : public Commander {
}
Status Execute(Server *svr, Connection *conn, std::string *output) override {
- if (range_type_ == kZRangeAuto || range_type_ == kZRangeRank) {
- redis::ZSet zset_db(svr->storage, conn->GetNamespace());
- std::vector<MemberScore> member_scores;
- auto s = zset_db.RangeByRank(args_[1], rank_spec_, &member_scores);
- if (!s.ok()) {
- return {Status::RedisExecErr, s.ToString()};
- }
+ redis::ZSet zset_db(svr->storage, conn->GetNamespace());
- if (!with_scores_) {
- output->append(redis::MultiLen(member_scores.size()));
- } else {
- output->append(redis::MultiLen(member_scores.size() * 2));
- }
+ std::vector<MemberScore> member_scores;
+ std::vector<std::string> members;
- for (const auto &ms : member_scores) {
- output->append(redis::BulkString(ms.member));
- if (with_scores_) output->append(redis::BulkString(util::Float2String(ms.score)));
- }
+ rocksdb::Status s;
- return Status::OK();
- } else if (range_type_ == kZRangeLex) {
- int size = 0;
- redis::ZSet zset_db(svr->storage, conn->GetNamespace());
- std::vector<std::string> members;
- auto s = zset_db.RangeByLex(args_[1], lex_spec_, &members, &size);
- if (!s.ok()) {
- return {Status::RedisExecErr, s.ToString()};
- }
+ switch (range_type_) {
+ case kZRangeAuto:
+ case kZRangeRank:
+ s = zset_db.RangeByRank(key_, rank_spec_, &member_scores, nullptr);
+ break;
+ case kZRangeScore:
+ s = zset_db.RangeByScore(key_, score_spec_, &member_scores, nullptr);
+ break;
+ case kZRangeLex:
+ s = zset_db.RangeByLex(key_, lex_spec_, &members, nullptr);
+ break;
+ }
+
+ if (!s.ok()) {
+ return {Status::RedisExecErr, s.ToString()};
+ }
- *output = redis::MultiBulkString(members, false);
+ if (!members.empty()) {
Review Comment:
It wouldn't reply to the request if the members and member_scores are empty lists, since the output is empty.
We still need to use MultiBulkString to reply the empty string array even if all of them are empty.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org