Skip to content

Commit 6a8cf82

Browse files
committed
feat:rtc can intercept more command
1 parent 26d10e6 commit 6a8cf82

1 file changed

Lines changed: 32 additions & 7 deletions

File tree

src/pika_client_conn.cc

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,37 @@ void PikaClientConn::ProcessMonitor(const PikaCmdArgsType& argv) {
258258
}
259259

260260
bool PikaClientConn::IsInterceptedByRTC(std::string& opt) {
261-
// currently we only Intercept: Get, HGet
262-
if (opt == kCmdNameGet && g_pika_conf->GetCacheString()) {
263-
return true;
261+
// only single key read command will be intercepted
262+
std::shared_ptr<Cmd> c_ptr = g_pika_cmd_table_manager->GetCmd(opt);
263+
if (!c_ptr) {
264+
return false;
264265
}
265-
if (opt == kCmdNameHGet && g_pika_conf->GetCacheHash()) {
266-
return true;
266+
267+
if (c_ptr->IsNeedReadCache()) {
268+
if (c_ptr->flag_ & kCmdFlagsOperateKey) {
269+
return true;
270+
}
271+
if (c_ptr->flag_ & kCmdFlagsKv) {
272+
if (g_pika_conf->GetCacheString()) {
273+
return true;
274+
}
275+
} else if (c_ptr->flag_ & kCmdFlagsZset) {
276+
if (g_pika_conf->GetCacheZset()) {
277+
return true;
278+
}
279+
} else if (c_ptr->flag_ & kCmdFlagsHash) {
280+
if (g_pika_conf->GetCacheHash()) {
281+
return true;
282+
}
283+
} else if (c_ptr->flag_ & kCmdFlagsList) {
284+
if (g_pika_conf->GetCacheList()) {
285+
return true;
286+
}
287+
} else if (c_ptr->flag_ & kCmdFlagsBit) {
288+
if (g_pika_conf->GetCacheBit()) {
289+
return true;
290+
}
291+
}
267292
}
268293
return false;
269294
}
@@ -349,7 +374,7 @@ bool PikaClientConn::ReadCmdInCache(const net::RedisCmdArgsType& argv, const std
349374
}
350375
// Initial
351376
c_ptr->Initial(argv, current_db_);
352-
// dont store cmd with too large key(only Get/HGet cmd can reach here)
377+
// dont store cmd with too large key
353378
// the cmd with large key should be non-exist in cache, except for pre-stored
354379
if (c_ptr->IsTooLargeKey(g_pika_conf->max_key_size_in_cache())) {
355380
resp_num--;
@@ -365,7 +390,7 @@ bool PikaClientConn::ReadCmdInCache(const net::RedisCmdArgsType& argv, const std
365390
// acl check failed
366391
return false;
367392
}
368-
// only read command(Get, HGet) will reach here, no need of record lock
393+
// only read command will reach here, no need of record lock
369394
bool read_status = c_ptr->DoReadCommandInCache();
370395
auto cmdstat_map = g_pika_cmd_table_manager->GetCommandStatMap();
371396
resp_num--;

0 commit comments

Comments
 (0)