From d99e1156cb1f8029626779a05105cd0ca4a659cd Mon Sep 17 00:00:00 2001 From: baotiao Date: Thu, 7 Sep 2017 19:00:05 +0800 Subject: [PATCH] improve redis protocol --- floyd/example/redis/raftis.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/floyd/example/redis/raftis.cc b/floyd/example/redis/raftis.cc index c3180eb..39aa2d8 100644 --- a/floyd/example/redis/raftis.cc +++ b/floyd/example/redis/raftis.cc @@ -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")) { @@ -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";