Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify the function return value,rename function name #36

Merged
merged 2 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ void CmdRes::SetRes(CmdRes::CmdRet _ret, const std::string& content) {
case kInvalidFloat:
SetLineString("-ERR value is not a valid float");
break;
break;
case kOverFlow:
SetLineString("-ERR increment or decrement would overflow");
break;
Expand Down Expand Up @@ -330,7 +329,7 @@ int PClient::handlePacket(const char* start, int bytes) {
// const PCommandInfo* info = PCommandTable::GetCommandInfo(cmdName_);

// if (!info) { // 如果这个命令不存在,那么就走新的命令处理流程
handlePacketNew();
executeCommand();
// return static_cast<int>(ptr - start);
// }

Expand Down Expand Up @@ -376,7 +375,7 @@ int PClient::handlePacket(const char* start, int bytes) {

// 为了兼容老的命令处理流程,新的命令处理流程在这里
// 后面可以把client这个类重构,完整的支持新的命令处理流程
void PClient::handlePacketNew() {
void PClient::executeCommand() {
auto [cmdPtr, ret] = g_pikiwidb->GetCmdTableManager().GetCommand(CmdName(), this);

if (!cmdPtr) {
Expand Down Expand Up @@ -520,7 +519,7 @@ bool PClient::isPeerMaster() const {
return repl_addr.GetIP() == PeerIP() && repl_addr.GetPort() == PeerPort();
}

int PClient::UniqueId() const {
int PClient::uniqueID() const {
if (auto c = getTcpConnection(); c) {
return c->GetUniqueId();
}
Expand All @@ -535,12 +534,12 @@ bool PClient::Watch(int dbno, const std::string& key) {

bool PClient::NotifyDirty(int dbno, const std::string& key) {
if (IsFlagOn(ClientFlagDirty)) {
INFO("client is already dirty {}", UniqueId());
INFO("client is already dirty {}", uniqueID());
return true;
}

if (watch_keys_[dbno].contains(key)) {
INFO("{} client become dirty because key {} in db {}", UniqueId(), key, dbno);
INFO("{} client become dirty because key {} in db {}", uniqueID(), key, dbno);
SetFlag(ClientFlagDirty);
return true;
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class CmdRes {
ret_ = kNone;
}

inline std::string Message() const { return message_; };
inline const std::string& Message() const { return message_; };

// Inline functions for Create Redis protocol
inline void AppendStringLen(int64_t ori) { RedisAppendLen(message_, ori, "$"); }
Expand Down Expand Up @@ -184,11 +184,11 @@ class PClient : public std::enable_shared_from_this<PClient>, public CmdRes {
private:
std::shared_ptr<TcpConnection> getTcpConnection() const { return tcp_connection_.lock(); }
int handlePacket(const char*, int);
void handlePacketNew();
void executeCommand();
int processInlineCmd(const char*, size_t, std::vector<std::string>&);
void reset();
bool isPeerMaster() const;
int UniqueId() const;
int uniqueID() const;

// TcpConnection's life is undetermined, so use weak ptr for safety.
std::weak_ptr<TcpConnection> tcp_connection_;
Expand Down