Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:pksetexat should update cache #2759

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading