Skip to content

Commit

Permalink
improve redis protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
baotiao committed Sep 7, 2017
1 parent 24424f0 commit d99e115
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions floyd/example/redis/raftis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ int MyConn::DealMessage() {

if (argv_.size() == 3 && (argv_[0] == "set" || argv_[0] == "SET")) {
s = f->Write(argv_[1], argv_[2]);
res = "+OK\r\n";
if (s.ok()) {
res = "+OK\r\n";
} else {
res = "-ERR write " + s.ToString() + " \r\n";
}
memcpy(wbuf_ + wbuf_len_, res.data(), res.size());
wbuf_len_ += res.size();
} else if (argv_.size() == 2 && (argv_[0] == "get" || argv_[0] == "GET")) {
Expand All @@ -61,10 +65,14 @@ int MyConn::DealMessage() {
wbuf_len_ += val.size();
memcpy(wbuf_ + wbuf_len_, "\r\n", 2);
wbuf_len_ += 2;
} else {
} else if (s.IsNotFound()) {
res = "$-1\r\n";
memcpy(wbuf_ + wbuf_len_, res.data(), res.size());
wbuf_len_ += res.size();
} else {
res = "-ERR read " + s.ToString() + " \r\n";
memcpy(wbuf_ + wbuf_len_, res.data(), res.size());
wbuf_len_ += res.size();
}
} else {
res = "+OK\r\n";
Expand Down

0 comments on commit d99e115

Please sign in to comment.