Skip to content
Merged
Changes from 4 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
22 changes: 19 additions & 3 deletions src/pika_client_conn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,29 @@ void PikaClientConn::ProcessMonitor(const PikaCmdArgsType& argv) {
}

bool PikaClientConn::IsInterceptedByRTC(std::string& opt) {
// currently we only Intercept: Get, HGet
if (opt == kCmdNameGet && g_pika_conf->GetCacheString()) {

static const std::unordered_set<std::string> intercepted_string_cmds = {
kCmdNameGet, kCmdNameStrlen, kCmdNameTtl
};

static const std::unordered_set<std::string> intercepted_hash_cmds = {
kCmdNameHGet, kCmdNameHMget, kCmdNameHExists, kCmdNameHVals, kCmdNameHStrlen
};

static const std::unordered_set<std::string> intercepted_list_cmds = {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

这里为什么是这些命令可以走 RTC 呢,具体的挑选逻辑可以列一下,然后 Zset 和 Set 类型我看好像没有添加上去

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

https://geelib.qihoo.net/geelib/knowledge/doc?spaceId=379&docId=198710
带注视的是要加的,zset 和 set没有常用的需要加的命令所以没添加
挑选的逻辑会按照:1只能是读命令并且不改变数值,2.命令访问的所有值都存储在cache中,不可以是一部分cache一部分DB 按照这个逻辑去挑选的

Copy link
Copy Markdown
Collaborator

@Mixficsol Mixficsol Sep 5, 2025

Choose a reason for hiding this comment

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

LLEN 命令能确保 List 的数据都在 Cache 里面吗,感觉计算长度这些命令不应该走 RTC 这种,因为如果内存占用满了会发生淘汰

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

LLEN 命令能确保 List 的数据都在 Cache 里面吗,感觉计算长度这些命令不应该走 RTC 这种,因为如果内存占用满了会发生淘汰

list的key的value值要不全部在cache要不全部在db中不会有一部分在cache一部分在db,这个命令走不走都可以吧,反正请求量也不会特别大

kCmdNameLLen
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add the missing header for std::unordered_set.

Relying on transitive includes is brittle; explicitly include the header.

Apply near the other STL includes:

 #include <utility>
 #include <vector>
+#include <unordered_set>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
static const std::unordered_set<std::string> intercepted_string_cmds = {
kCmdNameGet, kCmdNameStrlen, kCmdNameTtl
};
static const std::unordered_set<std::string> intercepted_hash_cmds = {
kCmdNameHGet, kCmdNameHMget, kCmdNameHExists, kCmdNameHVals, kCmdNameHStrlen
};
static const std::unordered_set<std::string> intercepted_list_cmds = {
kCmdNameLLen
};
#include <utility>
#include <vector>
#include <unordered_set>
🤖 Prompt for AI Agents
In src/pika_client_conn.cc around lines 277 to 288, the code uses
std::unordered_set but doesn't include its header; add an explicit #include
<unordered_set> near the other STL includes at the top of the file (grouped with
headers like <string>, <vector>, etc.) to avoid relying on transitive includes
and ensure the symbol is defined.

if (intercepted_string_cmds.count(opt) && g_pika_conf->GetCacheString()) {
return true;
}
if (opt == kCmdNameHGet && g_pika_conf->GetCacheHash()) {
if (intercepted_hash_cmds.count(opt) && g_pika_conf->GetCacheHash()) {
return true;
}
if (intercepted_list_cmds.count(opt) && g_pika_conf->GetCacheList()) {
return true;
}

return false;
Comment on lines 275 to 292
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Make opt a const reference and wire up list interception (or remove the dead set).

  • Parameter is not modified; use const std::string& to avoid implying mutation.
  • intercepted_list_cmds is defined but never used; either gate it with a list cache flag or drop it to avoid warnings.
-bool PikaClientConn::IsInterceptedByRTC(std::string& opt) {
+bool PikaClientConn::IsInterceptedByRTC(const std::string& opt) {
@@
   if (intercepted_hash_cmds.count(opt) && g_pika_conf->GetCacheHash()) {
     return true;
   }
 
+  // If list cache is supported, enable interception for list reads
+  if (intercepted_list_cmds.count(opt) && g_pika_conf->GetCacheList()) {
+    return true;
+  }
+
   return false;
 }

If GetCacheList() doesn’t exist yet, remove intercepted_list_cmds for now to prevent dead code warnings.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
bool PikaClientConn::IsInterceptedByRTC(std::string& opt) {
// currently we only Intercept: Get, HGet
if (opt == kCmdNameGet && g_pika_conf->GetCacheString()) {
static const std::unordered_set<std::string> intercepted_string_cmds = {
kCmdNameGet, kCmdNameStrlen, kCmdNameTtl
};
static const std::unordered_set<std::string> intercepted_hash_cmds = {
kCmdNameHGet, kCmdNameHMget, kCmdNameHExists, kCmdNameHVals, kCmdNameHStrlen
};
static const std::unordered_set<std::string> intercepted_list_cmds = {
kCmdNameLLen
};
if (intercepted_string_cmds.count(opt) && g_pika_conf->GetCacheString()) {
return true;
}
if (opt == kCmdNameHGet && g_pika_conf->GetCacheHash()) {
if (intercepted_hash_cmds.count(opt) && g_pika_conf->GetCacheHash()) {
return true;
}
return false;
bool PikaClientConn::IsInterceptedByRTC(const std::string& opt) {
static const std::unordered_set<std::string> intercepted_string_cmds = {
kCmdNameGet, kCmdNameStrlen, kCmdNameTtl
};
static const std::unordered_set<std::string> intercepted_hash_cmds = {
kCmdNameHGet, kCmdNameHMget, kCmdNameHExists, kCmdNameHVals, kCmdNameHStrlen
};
static const std::unordered_set<std::string> intercepted_list_cmds = {
kCmdNameLLen
};
if (intercepted_string_cmds.count(opt) && g_pika_conf->GetCacheString()) {
return true;
}
if (intercepted_hash_cmds.count(opt) && g_pika_conf->GetCacheHash()) {
return true;
}
// If list cache is supported, enable interception for list reads
if (intercepted_list_cmds.count(opt) && g_pika_conf->GetCacheList()) {
return true;
}
return false;
}
🤖 Prompt for AI Agents
In src/pika_client_conn.cc around lines 275 to 296, change the function
signature to take opt as a const std::string& (since it is not modified) and
eliminate the unused intercepted_list_cmds to avoid dead-code warnings; if a
GetCacheList() config accessor exists, instead wire intercepted_list_cmds into
the logic the same way as strings and hashes (check membership and return true
when GetCacheList() is enabled), otherwise remove the intercepted_list_cmds
definition and any references to it.

}

Expand Down
Loading