Skip to content

Commit

Permalink
bugfix in ZRevrangeCmd
Browse files Browse the repository at this point in the history
Axlgrep committed Jul 25, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 1233e87 commit 3446692
Showing 3 changed files with 19 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/pika_set.cc
Original file line number Diff line number Diff line change
@@ -378,7 +378,7 @@ void SRandmemberCmd::DoInitial(PikaCmdArgsType &argv, const CmdInfo* const ptr_i
void SRandmemberCmd::Do() {
std::vector<std::string> members;
rocksdb::Status s = g_pika_server->db()->SRandmember(key_, count_, &members);
if (s.ok()) {
if (s.ok() || s.IsNotFound()) {
if (!reply_arr && members.size()) {
res_.AppendStringLen(members[0].size());
res_.AppendContent(members[0]);
@@ -389,8 +389,6 @@ void SRandmemberCmd::Do() {
res_.AppendContent(member);
}
}
} else if (s.IsNotFound()) {
res_.AppendStringLen(-1);
} else {
res_.SetRes(CmdRes::kErrOther, s.ToString());
}
18 changes: 17 additions & 1 deletion src/pika_zset.cc
Original file line number Diff line number Diff line change
@@ -211,18 +211,34 @@ void ZRangeCmd::Do() {
return;
}

static void Calcmirror(int64_t &start, int64_t &stop, int32_t t_size) {
int64_t t_start = stop >= 0 ? stop : t_size + stop;
int64_t t_stop = start >= 0 ? start : t_size + start;
t_start = t_size - 1 - t_start;
t_stop = t_size - 1 - t_stop;
start = t_start >= 0 ? t_start : t_start - t_size;
stop = t_stop >= 0 ? t_stop : t_stop - t_size;
}

void ZRevrangeCmd::DoInitial(PikaCmdArgsType &argv, const CmdInfo* const ptr_info) {
if (!ptr_info->CheckArg(argv.size())) {
res_.SetRes(CmdRes::kWrongNum, kCmdNameZRevrange);
return;
}
ZsetRangeParentCmd::DoInitial(argv, NULL);
int32_t card = 0;
rocksdb::Status status = g_pika_server->db()->ZCard(key_, &card);
if (!status.ok() && !status.IsNotFound()) {
res_.SetRes(CmdRes::kErrOther, "zcard error");
return;
}
Calcmirror(start_, stop_, card);
}

void ZRevrangeCmd::Do() {
std::vector<blackwidow::ScoreMember> score_members;
rocksdb::Status s = g_pika_server->db()->ZRevrange(key_, start_, stop_, &score_members);
if (s.ok()) {
if (s.ok() || s.IsNotFound()) {
if (is_ws_) {
char buf[32];
int64_t len;

0 comments on commit 3446692

Please sign in to comment.