Skip to content

feat:add RTC command#3153

Merged
chejinge merged 5 commits intoOpenAtomFoundation:unstablefrom
chejinge:Rtc
Sep 5, 2025
Merged

feat:add RTC command#3153
chejinge merged 5 commits intoOpenAtomFoundation:unstablefrom
chejinge:Rtc

Conversation

@chejinge
Copy link
Copy Markdown
Collaborator

@chejinge chejinge commented Sep 2, 2025

const std::string kCmdNameGet = "get"; //1
const std::string kCmdNameStrlen = "strlen";//1

// Hash

const std::string kCmdNameHGet = "hget"; //1
const std::string kCmdNameHGetall = "hgetall"; //1
const std::string kCmdNameHExists = "hexists"; //1
const std::string kCmdNameHKeys = "hkeys";//1
const std::string kCmdNameHLen = "hlen";//1
const std::string kCmdNameHMget = "hmget";//1
const std::string kCmdNameHStrlen = "hstrlen";//1
const std::string kCmdNameHVals = "hvals";//1

// List

const std::string kCmdNameLLen = "llen";//1

// BitMap
const std::string kCmdNameBitCount = "bitcount";//1

// Zset
const std::string kCmdNameZCount = "zcount";//1

// Set

Summary by CodeRabbit

  • New Features
    • Expanded cache interception to include additional string and hash commands, respecting existing cache toggles for those types.
    • Simplified, consistent interception behavior across related string/hash operations for more reliable caching.
    • Note: list-command interception path was removed in this update.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Sep 2, 2025

Walkthrough

IsInterceptedByRTC was refactored to use two in-function static command-name sets (string and hash). The function returns true if the command is a member of the appropriate set and the corresponding g_pika_conf cache flag (GetCacheString or GetCacheHash) is enabled; list handling was removed.

Changes

Cohort / File(s) Summary
RTC interception logic
src/pika_client_conn.cc
Reworks PikaClientConn::IsInterceptedByRTC to use two static in-function command-name sets (intercepted_string_cmds, intercepted_hash_cmds) and to gate interception by the corresponding g_pika_conf toggles (GetCacheString, GetCacheHash); removes prior list-path and direct command-name comparisons.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor C as Client
    participant PC as PikaClientConn
    participant CS as Command Sets (string/hash)
    participant CC as Cache Config

    C->>PC: Send command
    PC->>CS: Check membership (string or hash set)
    alt In string set
        PC->>CC: Query GetCacheString
        alt Enabled
            note right of PC #D6EAF8: Intercept via RTC (string)
            PC-->>C: Intercepted (RTC)
        else Disabled
            note right of PC #F8EBE0: Skip interception
            PC-->>C: Normal handling
        end
    else In hash set
        PC->>CC: Query GetCacheHash
        alt Enabled
            note right of PC #D6EAF8: Intercept via RTC (hash)
            PC-->>C: Intercepted (RTC)
        else Disabled
            note right of PC #F8EBE0: Skip interception
            PC-->>C: Normal handling
        end
    else Not in any set
        note right of PC #F5F5F5: Not interceptable
        PC-->>C: Normal handling
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I nudge the code with curious paws and cheer,
Strings and hashes — I listen, sharp and near.
If cache is open, I catch the hop with glee,
If closed, I let the command wander free.
Thump-thump, a tidy tweak — carrot for me! 🥕🐇


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 475ccf2 and 4e227a9.

📒 Files selected for processing (1)
  • src/pika_client_conn.cc (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/pika_client_conn.cc
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Analyze (go)
  • GitHub Check: build_on_centos
  • GitHub Check: build_on_ubuntu
  • GitHub Check: build_on_macos
  • GitHub Check: Build Codis Docker image
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions Bot added ✏️ Feature New feature or request Invalid PR Title labels Sep 2, 2025
@chejinge chejinge changed the title add RTC command feat:add RTC command Sep 2, 2025
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/pika_client_conn.cc (1)

6-10: Add missing header for std::unordered_set.

This TU uses std::unordered_set but doesn’t include its header. Relying on transitive includes is brittle and may fail CI with -Werror/-Wpedantic.

 #include <utility>
 #include <vector>
+#include <unordered_set>
🧹 Nitpick comments (1)
src/pika_client_conn.cc (1)

389-407: Refresh the outdated comment to reflect the widened interception set.

The comment still claims only Get/HGet reach the cache path.

-  // dont store cmd with too large key(only Get/HGet cmd can reach here)
-  // the cmd with large key should be non-exist in cache, except for pre-stored
+  // Don't store cmds with too-large keys.
+  // Only read-only cmds reach here via RTC (e.g., GET/STRLEN/TTL, HGET/HMGET/HEXISTS/HVALS/HSTRLEN, LLEN).
+  // Large keys should be non-existent in cache, except for pre-stored entries.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 6d4b8d7 and 6d3194a.

📒 Files selected for processing (1)
  • src/pika_client_conn.cc (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Analyze (go)
  • GitHub Check: build_on_ubuntu
  • GitHub Check: build_on_centos
🔇 Additional comments (1)
src/pika_client_conn.cc (1)

275-287: Cache fast-path available for all newly intercepted commands. STRLEN, TTL, HGET, HEXISTS, HMGET, HSTRLEN, HVALS and LLEN are all registered with kCmdFlagsReadCache (and fast-path flags) and will be handled by Cmd::DoReadCommandInCache(). TTL remains cached—verify that any potential staleness meets your requirements.

Comment thread src/pika_client_conn.cc
Comment on lines 275 to 296
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;
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.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
src/pika_client_conn.cc (1)

275-275: Make opt a const reference.

The parameter isn’t modified. Prefer const std::string& to avoid accidental mutation and enable binding to temporaries.

Apply:

-bool PikaClientConn::IsInterceptedByRTC(std::string& opt) {
+bool PikaClientConn::IsInterceptedByRTC(const std::string& opt) {

Remember to update the declaration in the corresponding header as well.

🧹 Nitpick comments (2)
src/pika_client_conn.cc (2)

289-297: Micro: short‑circuit on disabled caches before hashing.

Avoid set lookups when the related cache is off.

Example:

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

277-288: Restrict intercepted_*_cmds to GET and HGET only
Only GET and HGET reach the RTC read path (per the “only read command(Get, HGet) will reach here” comment), so remove Strlen, Ttl, HMget, HExists, HVals, HStrlen and LLen from the intercepted_*_cmds sets to avoid spurious cache_miss_in_rtc flags.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 6d3194a and 475ccf2.

📒 Files selected for processing (1)
  • src/pika_client_conn.cc (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: build_on_centos
  • GitHub Check: build_on_ubuntu
  • GitHub Check: Analyze (go)
🔇 Additional comments (2)
src/pika_client_conn.cc (2)

295-297: Nice: list interception is now gated on GetCacheList.

This wires previously unused intercepted_list_cmds into config properly.


292-297: Confirmed GetCacheList() exists in PikaConf. No further action required.

Comment thread src/pika_client_conn.cc Outdated
Comment on lines +277 to +288
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
};

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.

Comment thread src/pika_client_conn.cc Outdated
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,这个命令走不走都可以吧,反正请求量也不会特别大

Removed unused intercepted_list_cmds set from pika_client_conn.cc.
@chejinge chejinge merged commit 60a4a8e into OpenAtomFoundation:unstable Sep 5, 2025
13 checks passed
byseea11 pushed a commit to byseea11/pikiwidb that referenced this pull request Sep 27, 2025
Removed unused intercepted_list_cmds set from pika_client_conn.cc.

---------

Co-authored-by: chejinge <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✏️ Feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants