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

PERSIST returns 0 when key has no expiry #1178

Merged
merged 1 commit into from
May 3, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/server/generic_family.cc
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ OpStatus OpPersist(const OpArgs& op_args, string_view key) {
return db_slice.UpdateExpire(op_args.db_cntx.db_index, it, 0) ? OpStatus::OK
: OpStatus::SKIPPED;
}
return OpStatus::OK; // fall though - this is the default
return OpStatus::SKIPPED; // fall though - key does not have expiry
}
}

Expand Down Expand Up @@ -710,7 +710,10 @@ void GenericFamily::Persist(CmdArgList args, ConnectionContext* cntx) {
auto cb = [&](Transaction* t, EngineShard* shard) { return OpPersist(t->GetOpArgs(shard), key); };

OpStatus status = cntx->transaction->ScheduleSingleHop(move(cb));
(*cntx)->SendLong(status == OpStatus::OK);
if (status == OpStatus::OK)
(*cntx)->SendLong(1);
else
(*cntx)->SendLong(0);
}

void GenericFamily::Expire(CmdArgList args, ConnectionContext* cntx) {
Expand Down
7 changes: 5 additions & 2 deletions src/server/generic_family_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -415,13 +415,16 @@ TEST_F(GenericFamilyTest, Time) {
TEST_F(GenericFamilyTest, Persist) {
auto resp = Run({"set", "mykey", "somevalue"});
EXPECT_EQ(resp, "OK");
// Key without expiration time - return 1
EXPECT_EQ(1, CheckedInt({"persist", "mykey"}));
// Key without expiration time - return 0
EXPECT_EQ(0, CheckedInt({"persist", "mykey"}));
EXPECT_EQ(-1, CheckedInt({"TTL", "mykey"}));
// set expiration time and try again
resp = Run({"EXPIRE", "mykey", "10"});
EXPECT_EQ(10, CheckedInt({"TTL", "mykey"}));
EXPECT_EQ(1, CheckedInt({"persist", "mykey"}));
EXPECT_EQ(-1, CheckedInt({"TTL", "mykey"}));
// persist on key that does not exist should also return 0
EXPECT_EQ(0, CheckedInt({"persist", "keythatdoesnotexist"}));
}

TEST_F(GenericFamilyTest, Dump) {
Expand Down