Skip to content

Commit

Permalink
fix srandmember (OpenAtomFoundation#224)
Browse files Browse the repository at this point in the history
* fix srandmember

* bugfix
  • Loading branch information
Leviathan1995 authored and KernelMaker committed Dec 21, 2017
1 parent 8cc011d commit 45659bd
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/pika_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,16 @@ void SRandmemberCmd::Do() {
std::vector<std::string> members;
nemo::Status s = g_pika_server->db()->SRandMember(key_, members, count_);
if (s.ok() || s.IsNotFound()) {
res_.AppendArrayLen(members.size());
std::vector<std::string>::const_iterator iter = members.begin();
for (; iter != members.end(); iter++) {
res_.AppendStringLen(iter->size());
res_.AppendContent(*iter);
if (members.size() == 1) {
res_.AppendStringLen(members[0].size());
res_.AppendContent(members[0]);
} else {
res_.AppendArrayLen(members.size());
std::vector<std::string>::const_iterator iter = members.begin();
for (; iter != members.end(); iter++) {
res_.AppendStringLen(iter->size());
res_.AppendContent(*iter);
}
}
} else {
res_.SetRes(CmdRes::kErrOther, s.ToString());
Expand Down

0 comments on commit 45659bd

Please sign in to comment.