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

fix:Add the output data of command 'info keyspace 0' to the output of com… #2603

Merged
merged 4 commits into from
Apr 29, 2024
Merged
Changes from 2 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
23 changes: 18 additions & 5 deletions src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ void InfoCmd::DoInitial() {

if (strcasecmp(argv_[1].data(), kAllSection.data()) == 0) {
info_section_ = kInfoAll;
keyspace_scan_dbs_ = g_pika_server->GetAllDBName();
} else if (strcasecmp(argv_[1].data(), kServerSection.data()) == 0) {
info_section_ = kInfoServer;
} else if (strcasecmp(argv_[1].data(), kClientsSection.data()) == 0) {
Expand All @@ -810,6 +811,7 @@ void InfoCmd::DoInitial() {
info_section_ = kInfoKeyspace;
if (argc == 2) {
LogCommand();

return;
}
// info keyspace [ 0 | 1 | off ]
Expand Down Expand Up @@ -1194,15 +1196,27 @@ void InfoCmd::InfoKeyspace(std::string& info) {
std::stringstream tmp_stream;
tmp_stream << "# Keyspace"
<< "\r\n";
if (argv_.size()> 1 && strcasecmp(argv_[1].data(), kAllSection.data()) == 0) {
Copy link
Collaborator

@Mixficsol Mixficsol Apr 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  if (argv_.size() > 1 && strcasecmp(argv_[1].data(), kAllSection.data()) == 0) {
    tmp_stream << "# Start async statistics\r\n";
  } else if (argv_.size() == 3 && strcasecmp(argv_[1].data(), kKeyspaceSection.data()) == 0) {
    tmp_stream << "# Start async statistics\r\n";    
  } else {
    tmp_stream << "# Use \"info keyspace 1\" to do async statistics\r\n";  
  }

这样写是不是更好一些

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的,我过于执着分支了,你的代码健壮性和清晰度都更好

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

过奖了

// Command=>"info all"
tmp_stream << "# Start async statistics\r\n";
} else if (argv_.size() > 2 && strcasecmp(argv_[1].data(), kKeyspaceSection.data()) == 0) {

if (argv_.size() == 3) { // command => `info keyspace 1`
if (argv_.size() == 3) {
tmp_stream << "# Start async statistics\r\n"; // Command=>"info keyspace 1|0"
} else {
tmp_stream << "# Use \"info keyspace 1\" to do async statistics\r\n"; // Command=>"info keyspace"
}
} else {
tmp_stream << "# Use \"info keyspace 1\" to do async statistics\r\n"; // Command=>"info"
}
/**if (argv_.size() == 3){ // command => `info keyspace 1` or `info all`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要的代码直接删除即可

tmp_stream << "# Start async statistics"
<< "\r\n";
} else { // command => `info keyspace` or `info`
} else { // command => `info keyspace`
tmp_stream << "# Use \"info keyspace 1\" do async statistics"
<< "\r\n";
}

**/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

删除

std::shared_lock rwl(g_pika_server->dbs_rw_);
for (const auto& db_item : g_pika_server->dbs_) {
if (keyspace_scan_dbs_.find(db_item.first) != keyspace_scan_dbs_.end()) {
Expand All @@ -1225,7 +1239,7 @@ void InfoCmd::InfoKeyspace(std::string& info) {
tmp_stream << "# Duration: " << std::to_string(duration) + "s"
<< "\r\n";
}

tmp_stream << db_name << " Strings_keys=" << key_infos[0].keys << ", expires=" << key_infos[0].expires
<< ", invalid_keys=" << key_infos[0].invaild_keys << "\r\n";
tmp_stream << db_name << " Hashes_keys=" << key_infos[1].keys << ", expires=" << key_infos[1].expires
Expand All @@ -1239,7 +1253,6 @@ void InfoCmd::InfoKeyspace(std::string& info) {
}
}
info.append(tmp_stream.str());

if (rescan_) {
g_pika_server->DoSameThingSpecificDB(keyspace_scan_dbs_, {TaskType::kStartKeyScan});
}
Expand Down
Loading