Skip to content

Commit

Permalink
fix:pksetexat should update cache (#2759)
Browse files Browse the repository at this point in the history
Co-authored-by: chejinge <[email protected]>
  • Loading branch information
chejinge and brother-jin authored Jun 25, 2024
1 parent e5dd45a commit 3fce772
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/pika_kv.h
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,8 @@ class PKSetexAtCmd : public Cmd {
return res;
}
void Do() override;
void DoThroughDB() override;
void DoUpdateCache() override;
void Split(const HintKeys& hint_keys) override {};
void Merge() override {};
Cmd* Clone() override { return new PKSetexAtCmd(*this); }
Expand Down
2 changes: 1 addition & 1 deletion src/pika_command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ void InitCmdTable(CmdTable* cmd_table) {
cmd_table->insert(std::pair<std::string, std::unique_ptr<Cmd>>(kCmdNameScanx, std::move(scanxptr)));
////PKSetexAtCmd
std::unique_ptr<Cmd> pksetexatptr = std::make_unique<PKSetexAtCmd>(
kCmdNamePKSetexAt, 4, kCmdFlagsWrite | kCmdFlagsKv | kCmdFlagsSlow);
kCmdNamePKSetexAt, 4, kCmdFlagsWrite | kCmdFlagsKv | kCmdFlagsSlow | kCmdFlagsDoThroughDB | kCmdFlagsUpdateCache);
cmd_table->insert(std::pair<std::string, std::unique_ptr<Cmd>>(kCmdNamePKSetexAt, std::move(pksetexatptr)));
////PKScanRange
std::unique_ptr<Cmd> pkscanrangeptr = std::make_unique<PKScanRangeCmd>(
Expand Down
16 changes: 16 additions & 0 deletions src/pika_kv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1877,6 +1877,22 @@ void PKSetexAtCmd::Do() {
}
}

void PKSetexAtCmd::DoThroughDB() {
Do();
}

void PKSetexAtCmd::DoUpdateCache() {
if (s_.ok()) {
auto expire = time_stamp_ - static_cast<int64_t>(std::time(nullptr));
std::string CachePrefixKeyK = PCacheKeyPrefixK + key_;
if (expire <= 0) [[unlikely]] {
db_->cache()->Del({CachePrefixKeyK});
return;
}
db_->cache()->Setxx(CachePrefixKeyK, value_, expire);
}
}

void PKScanRangeCmd::DoInitial() {
if (!CheckArg(argv_.size())) {
res_.SetRes(CmdRes::kWrongNum, kCmdNamePKScanRange);
Expand Down

0 comments on commit 3fce772

Please sign in to comment.