diff --git a/src/client.h b/src/client.h index f1bc2e4db..c768b9ae0 100644 --- a/src/client.h +++ b/src/client.h @@ -107,6 +107,9 @@ enum class ClientState { kClosed, }; +constexpr const char* ErrTypeMessage = + "Invalid argument: WRONGTYPE Operation against a key holding the wrong kind of value"; + class DB; struct PSlaveInfo; diff --git a/src/cmd_hash.cc b/src/cmd_hash.cc index 76e9bc4c0..97d74c21c 100644 --- a/src/cmd_hash.cc +++ b/src/cmd_hash.cc @@ -40,7 +40,7 @@ void HSetCmd::DoCmd(PClient* client) { s = PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->HSet(client->Key(), field, value, &temp); if (s.ok()) { ret += temp; - } else if (s.IsInvalidArgument()) { + } else if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); return; } else { @@ -66,7 +66,7 @@ void HGetCmd::DoCmd(PClient* client) { storage::Status s = PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->HGet(client->Key(), field, &value); if (s.ok()) { client->AppendString(value); - } else if (s.IsInvalidArgument()) { + } else if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); } else if (s.IsNotFound()) { client->AppendString(""); @@ -87,7 +87,7 @@ void HDelCmd::DoCmd(PClient* client) { int32_t res{}; std::vector fields(client->argv_.begin() + 2, client->argv_.end()); auto s = PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->HDel(client->Key(), fields, &res); - if (s.IsInvalidArgument()) { + if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); return; } @@ -115,7 +115,7 @@ void HMSetCmd::DoCmd(PClient* client) { storage::Status s = PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->HMSet(client->Key(), client->Fvs()); if (s.ok()) { client->SetRes(CmdRes::kOK); - } else if (s.IsInvalidArgument()) { + } else if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); } else { client->SetRes(CmdRes::kErrOther, s.ToString()); @@ -145,7 +145,7 @@ void HMGetCmd::DoCmd(PClient* client) { client->AppendString(""); } } - } else if (s.IsInvalidArgument()) { + } else if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); } else { client->SetRes(CmdRes::kErrOther, s.ToString()); @@ -197,7 +197,7 @@ void HGetAllCmd::DoCmd(PClient* client) { if (s.ok() || s.IsNotFound()) { client->AppendArrayLen(total_fv * 2); client->AppendStringRaw(raw); - } else if (s.IsInvalidArgument()) { + } else if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); } else { client->SetRes(CmdRes::kErrOther, s.ToString()); @@ -223,7 +223,7 @@ void HKeysCmd::DoCmd(PClient* client) { } // update fields client->Fields() = std::move(fields); - } else if (s.IsInvalidArgument()) { + } else if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); } else { client->SetRes(CmdRes::kErrOther, s.ToString()); @@ -243,7 +243,7 @@ void HLenCmd::DoCmd(PClient* client) { auto s = PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->HLen(client->Key(), &len); if (s.ok() || s.IsNotFound()) { client->AppendInteger(len); - } else if (s.IsInvalidArgument()) { + } else if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); } else { client->SetRes(CmdRes::kErrOther, "something wrong in hlen"); @@ -263,7 +263,7 @@ void HStrLenCmd::DoCmd(PClient* client) { auto s = PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->HStrlen(client->Key(), client->argv_[2], &len); if (s.ok() || s.IsNotFound()) { client->AppendInteger(len); - } else if (s.IsInvalidArgument()) { + } else if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); } else { client->SetRes(CmdRes::kErrOther, "something wrong in hstrlen"); @@ -340,7 +340,7 @@ void HValsCmd::DoCmd(PClient* client) { storage::Status s = PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->HVals(client->Key(), &valueVec); if (s.ok() || s.IsNotFound()) { client->AppendStringVector(valueVec); - } else if (s.IsInvalidArgument()) { + } else if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); } else { client->SetRes(CmdRes::kErrOther, "hvals cmd error"); @@ -372,7 +372,7 @@ void HIncrbyFloatCmd::DoCmd(PClient* client) { ->HIncrbyfloat(client->Key(), client->argv_[2], client->argv_[3], &newValue); if (s.ok() || s.IsNotFound()) { client->AppendString(newValue); - } else if (s.IsInvalidArgument()) { + } else if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); } else { client->SetRes(CmdRes::kErrOther, "hvals cmd error"); @@ -395,7 +395,7 @@ void HSetNXCmd::DoCmd(PClient* client) { ->HSetnx(client->Key(), client->argv_[2], client->argv_[3], &temp); if (s.ok()) { client->AppendInteger(temp); - } else if (s.IsInvalidArgument()) { + } else if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); } else { client->SetRes(CmdRes::kSyntaxErr, "hsetnx cmd error"); @@ -423,7 +423,7 @@ void HIncrbyCmd::DoCmd(PClient* client) { PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->HIncrby(client->Key(), client->argv_[2], int_by, &temp); if (s.ok() || s.IsNotFound()) { client->AppendInteger(temp); - } else if (s.IsInvalidArgument()) { + } else if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); } else { client->SetRes(CmdRes::kErrOther, "hincrby cmd error"); diff --git a/src/cmd_list.cc b/src/cmd_list.cc index 3c48ec221..fd7caaa0e 100644 --- a/src/cmd_list.cc +++ b/src/cmd_list.cc @@ -25,7 +25,7 @@ void LPushCmd::DoCmd(PClient* client) { PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->LPush(client->Key(), list_values, &reply_num); if (s.ok()) { client->AppendInteger(reply_num); - } else if (s.IsInvalidArgument()) { + } else if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); } else { client->SetRes(CmdRes::kSyntaxErr, "lpush cmd error"); @@ -47,7 +47,7 @@ void LPushxCmd::DoCmd(PClient* client) { PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->LPushx(client->Key(), list_values, &reply_num); if (s.ok() || s.IsNotFound()) { client->AppendInteger(reply_num); - } else if (s.IsInvalidArgument()) { + } else if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); } else { client->SetRes(CmdRes::kErrOther, s.ToString()); @@ -69,7 +69,7 @@ void RPushCmd::DoCmd(PClient* client) { PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->RPush(client->Key(), list_values, &reply_num); if (s.ok()) { client->AppendInteger(reply_num); - } else if (s.IsInvalidArgument()) { + } else if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); } else { client->SetRes(CmdRes::kSyntaxErr, "rpush cmd error"); @@ -91,7 +91,7 @@ void RPushxCmd::DoCmd(PClient* client) { PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->RPushx(client->Key(), list_values, &reply_num); if (s.ok() || s.IsNotFound()) { client->AppendInteger(reply_num); - } else if (s.IsInvalidArgument()) { + } else if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); } else { client->SetRes(CmdRes::kErrOther, s.ToString()); @@ -111,7 +111,7 @@ void LPopCmd::DoCmd(PClient* client) { storage::Status s = PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->LPop(client->Key(), 1, &elements); if (s.ok()) { client->AppendString(elements[0]); - } else if (s.IsInvalidArgument()) { + } else if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); } else if (s.IsNotFound()) { client->AppendStringLen(-1); @@ -133,7 +133,7 @@ void RPopCmd::DoCmd(PClient* client) { storage::Status s = PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->RPop(client->Key(), 1, &elements); if (s.ok()) { client->AppendString(elements[0]); - } else if (s.IsInvalidArgument()) { + } else if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); } else if (s.IsNotFound()) { client->AppendStringLen(-1); @@ -160,7 +160,7 @@ void LRangeCmd::DoCmd(PClient* client) { } storage::Status s = PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->LRange(client->Key(), start_index, end_index, &ret); - if (s.IsInvalidArgument()) { + if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); return; } @@ -192,7 +192,7 @@ void LRemCmd::DoCmd(PClient* client) { PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->LRem(client->Key(), freq_, client->argv_[3], &reply_num); if (s.ok() || s.IsNotFound()) { client->AppendInteger(reply_num); - } else if (s.IsInvalidArgument()) { + } else if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); } else { client->SetRes(CmdRes::kErrOther, "lrem cmd error"); @@ -219,7 +219,7 @@ void LTrimCmd::DoCmd(PClient* client) { PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->LTrim(client->Key(), start_index, end_index); if (s.ok() || s.IsNotFound()) { client->SetRes(CmdRes::kOK); - } else if (s.IsInvalidArgument()) { + } else if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); } else { client->SetRes(CmdRes::kSyntaxErr, "ltrim cmd error"); @@ -249,7 +249,7 @@ void LSetCmd::DoCmd(PClient* client) { PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->LSet(client->Key(), val, client->argv_[3]); if (s.ok()) { client->SetRes(CmdRes::kOK); - } else if (s.IsInvalidArgument()) { + } else if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); } else if (s.IsNotFound()) { client->SetRes(CmdRes::kNotFound); @@ -284,7 +284,7 @@ void LInsertCmd::DoCmd(PClient* client) { storage::Status s = PSTORE.GetBackend(client->GetCurrentDB()) ->GetStorage() ->LInsert(client->Key(), before_or_after, client->argv_[3], client->argv_[4], &ret); - if (s.IsInvalidArgument()) { + if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); return; } @@ -315,7 +315,7 @@ void LIndexCmd::DoCmd(PClient* client) { storage::Status s = PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->LIndex(client->Key(), freq_, &value); if (s.ok()) { client->AppendString(value); - } else if (s.IsInvalidArgument()) { + } else if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); } else if (s.IsNotFound()) { client->AppendStringLen(-1); @@ -337,7 +337,7 @@ void LLenCmd::DoCmd(PClient* client) { storage::Status s = PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->LLen(client->Key(), &llen); if (s.ok() || s.IsNotFound()) { client->AppendInteger(static_cast(llen)); - } else if (s.IsInvalidArgument()) { + } else if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); } else { client->SetRes(CmdRes::kErrOther, s.ToString()); diff --git a/src/cmd_set.cc b/src/cmd_set.cc index 6d0731a19..8e3372f73 100644 --- a/src/cmd_set.cc +++ b/src/cmd_set.cc @@ -42,7 +42,7 @@ void SAddCmd::DoCmd(PClient* client) { storage::Status s = PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->SAdd(client->Key(), members, &ret); if (s.ok()) { client->AppendInteger(ret); - } else if (s.IsInvalidArgument()) { + } else if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); } else { client->SetRes(CmdRes::kSyntaxErr, "sadd cmd error"); @@ -69,7 +69,7 @@ void SUnionStoreCmd::DoCmd(PClient* client) { if (!s.ok()) { client->SetRes(CmdRes::kSyntaxErr, "sunionstore cmd error"); } - if (s.IsInvalidArgument()) { + if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); } client->AppendInteger(ret); @@ -91,7 +91,7 @@ void SInterCmd::DoCmd(PClient* client) { client->SetRes(CmdRes::kErrOther, "sinter cmd error"); return; } - if (s.IsInvalidArgument()) { + if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); } client->AppendStringVector(res_vt); @@ -113,7 +113,7 @@ void SRemCmd::DoCmd(PClient* client) { if (!s.ok()) { client->SetRes(CmdRes::kErrOther, "srem cmd error"); } - if (s.IsInvalidArgument()) { + if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); } client->AppendInteger(reply_num); @@ -134,7 +134,7 @@ void SUnionCmd::DoCmd(PClient* client) { if (!s.ok()) { client->SetRes(CmdRes::kErrOther, "sunion cmd error"); } - if (s.IsInvalidArgument()) { + if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); } client->AppendStringVector(res_vt); @@ -156,7 +156,7 @@ void SInterStoreCmd::DoCmd(PClient* client) { storage::Status s = PSTORE.GetBackend(client->GetCurrentDB()) ->GetStorage() ->SInterstore(client->Key(), inter_keys, value_to_dest, &reply_num); - if (s.IsInvalidArgument()) { + if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); return; } @@ -177,7 +177,7 @@ bool SCardCmd::DoInitial(PClient* client) { void SCardCmd::DoCmd(PClient* client) { int32_t reply_Num = 0; storage::Status s = PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->SCard(client->Key(), &reply_Num); - if (s.IsInvalidArgument()) { + if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); return; } @@ -198,7 +198,7 @@ void SMoveCmd::DoCmd(PClient* client) { storage::Status s = PSTORE.GetBackend(client->GetCurrentDB()) ->GetStorage() ->SMove(client->argv_[1], client->argv_[2], client->argv_[3], &reply_num); - if (s.IsInvalidArgument()) { + if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); return; } @@ -231,7 +231,7 @@ void SRandMemberCmd::DoCmd(PClient* client) { std::vector vec_ret; storage::Status s = PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->SRandmember(client->Key(), this->num_rand, &vec_ret); - if (s.IsInvalidArgument()) { + if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); return; } @@ -300,7 +300,7 @@ bool SMembersCmd::DoInitial(PClient* client) { void SMembersCmd::DoCmd(PClient* client) { std::vector delete_members; storage::Status s = PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->SMembers(client->Key(), &delete_members); - if (s.IsInvalidArgument()) { + if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); return; } @@ -323,7 +323,7 @@ void SDiffCmd::DoCmd(PClient* client) { std::vector diff_members; std::vector diff_keys(client->argv_.begin() + 1, client->argv_.end()); storage::Status s = PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->SDiff(diff_keys, &diff_members); - if (s.IsInvalidArgument()) { + if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); return; } @@ -349,7 +349,7 @@ void SDiffstoreCmd::DoCmd(PClient* client) { storage::Status s = PSTORE.GetBackend(client->GetCurrentDB()) ->GetStorage() ->SDiffstore(client->Key(), diffstore_keys, value_to_dest, &reply_num); - if (s.IsInvalidArgument()) { + if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); return; } diff --git a/src/cmd_zset.cc b/src/cmd_zset.cc index e4096e963..1b48ee3f9 100644 --- a/src/cmd_zset.cc +++ b/src/cmd_zset.cc @@ -112,7 +112,7 @@ void ZAddCmd::DoCmd(PClient* client) { PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->ZAdd(client->Key(), score_members_, &count); if (s.ok()) { client->AppendInteger(count); - } else if (s.IsInvalidArgument()) { + } else if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); } else { client->SetRes(CmdRes::kErrOther, s.ToString()); @@ -170,7 +170,7 @@ void ZRevrangeCmd::DoCmd(PClient* client) { client->AppendContent(sm.member); } } - } else if (s.IsInvalidArgument()) { + } else if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); } else { client->SetRes(CmdRes::kErrOther, s.ToString()); @@ -232,7 +232,7 @@ void ZRangebyscoreCmd::DoCmd(PClient* client) { ->GetStorage() ->ZRangebyscore(client->Key(), min_score, max_score, left_close, right_close, &score_members); - if (s.IsInvalidArgument()) { + if (s.ToString() == ErrTypeMessage) { client->SetRes(CmdRes::kmultikey); return; }