Skip to content

Commit ddf85e9

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

1 file changed

Lines changed: 36 additions & 7 deletions

File tree

src/pika_client_conn.cc

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,41 @@ 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+
}else if (c_ptr->flag_ & kCmdFlagsSet) {
292+
if (g_pika_conf->GetCacheSet()) {
293+
return true;
294+
}
295+
}
267296
}
268297
return false;
269298
}
@@ -349,7 +378,7 @@ bool PikaClientConn::ReadCmdInCache(const net::RedisCmdArgsType& argv, const std
349378
}
350379
// Initial
351380
c_ptr->Initial(argv, current_db_);
352-
// dont store cmd with too large key(only Get/HGet cmd can reach here)
381+
// dont store cmd with too large key
353382
// the cmd with large key should be non-exist in cache, except for pre-stored
354383
if (c_ptr->IsTooLargeKey(g_pika_conf->max_key_size_in_cache())) {
355384
resp_num--;
@@ -365,7 +394,7 @@ bool PikaClientConn::ReadCmdInCache(const net::RedisCmdArgsType& argv, const std
365394
// acl check failed
366395
return false;
367396
}
368-
// only read command(Get, HGet) will reach here, no need of record lock
397+
// only read command will reach here, no need of record lock
369398
bool read_status = c_ptr->DoReadCommandInCache();
370399
auto cmdstat_map = g_pika_cmd_table_manager->GetCommandStatMap();
371400
resp_num--;

0 commit comments

Comments
 (0)