Skip to content

Commit

Permalink
fix error and make some modify
Browse files Browse the repository at this point in the history
  • Loading branch information
gukj-spel committed Aug 27, 2024
1 parent b8b6f0a commit ae02b7a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/client_map.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "client_map.h"
#include "log.h"

namespace pikiwidb {
namespace kiwi {

uint32_t ClientMap::GetAllClientInfos(std::vector<ClientInfo>& results) {
// client info string type: ip, port, fd.
Expand Down Expand Up @@ -100,4 +100,4 @@ bool ClientMap::KillClientById(int client_id) {
return false;
}

} // namespace pikiwidb
} // namespace kiwi
6 changes: 3 additions & 3 deletions src/client_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <string>
#include "client.h"

namespace pikiwidb {
namespace kiwi {
class ClientMap {
private:
ClientMap() = default;
Expand All @@ -26,7 +26,7 @@ class ClientMap {
ClientMap& operator=(const ClientMap&) = delete;

// client info function
pikiwidb::ClientInfo GetClientsInfoById(int id);
kiwi::ClientInfo GetClientsInfoById(int id);
uint32_t GetAllClientInfos(std::vector<ClientInfo>& results);

bool AddClient(int id, std::weak_ptr<PClient>);
Expand All @@ -38,4 +38,4 @@ class ClientMap {
bool KillClientByAddrPort(const std::string& addr_port);
};

} // namespace pikiwidb
} // namespace kiwi
13 changes: 6 additions & 7 deletions src/cmd_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ CmdClientSetname::CmdClientSetname(const std::string& name, int16_t arity)

bool CmdClientSetname::DoInitial(PClient* client) { return true; }

void pikiwidb::CmdClientSetname::DoCmd(PClient* client) {
void kiwi::CmdClientSetname::DoCmd(PClient* client) {
client->SetName(client->argv_[2]);
client->SetRes(CmdRes::kOK);
}
Expand Down Expand Up @@ -695,7 +695,7 @@ bool CmdClientKill::DoInitial(PClient* client) {

void CmdClientKill::DoCmd(PClient* client) {
bool ret;
auto& client_map = pikiwidb::ClientMap::getInstance();
auto& client_map = kiwi::ClientMap::getInstance();
switch (kill_type_) {
case Type::ALL: {
ret = client_map.KillAllClients();
Expand Down Expand Up @@ -740,7 +740,7 @@ void CmdClientList::DoCmd(PClient* client) {
auto& client_map = ClientMap::getInstance();
switch (list_type_) {
case Type::DEFAULT: {
std::vector<pikiwidb::ClientInfo> client_infos;
std::vector<kiwi::ClientInfo> client_infos;
client_map.GetAllClientInfos(client_infos);
client->AppendArrayLen(client_infos.size());
if (client_infos.size() == 0) {
Expand All @@ -766,10 +766,9 @@ void CmdClientList::DoCmd(PClient* client) {
client->SetRes(CmdRes::kErrOther, "Invalid client id");
return;
}
char buf[128];
snprintf(buf, sizeof(buf), "ID=%ld IP=%s PORT=%d\n", client_info.client_id, client_info.ip.c_str(),
client_info.port);
client->AppendString(std::string(buf));
std::string result =
fmt::format("ID={} IP={} PORT={}\n", client_info.client_id, client_info.ip, client_info.port);
client->AppendString(result);
} catch (const std::exception& e) {
client->SetRes(CmdRes::kErrOther, "Invalid client id");
return;
Expand Down

0 comments on commit ae02b7a

Please sign in to comment.