fix(set_family): Update object time during SET FIELDEXPIRE (#4903)

StringSet object doesn't update time when FIELDEXPIRE is called. It will
use base time when object is created. Update object time when we want to
expire field in SET object.

Fixes #4894

Signed-off-by: mkaruza <mario@dragonflydb.io>
This commit is contained in:
mkaruza 2025-04-14 13:14:40 +02:00 committed by GitHub
parent 39a00806c9
commit ea17fc9893
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View file

@ -848,8 +848,10 @@ TEST_F(GenericFamilyTest, JsonType) {
TEST_F(GenericFamilyTest, FieldExpireSet) {
Run({"SADD", "key", "a", "b", "c"});
AdvanceTime(2'000);
EXPECT_THAT(Run({"FIELDEXPIRE", "key", "10", "a", "b", "c"}),
RespArray(ElementsAre(IntArg(1), IntArg(1), IntArg(1))));
EXPECT_EQ(10, CheckedInt({"fieldttl", "key", "a"}));
AdvanceTime(10'000);
EXPECT_THAT(Run({"SMEMBERS", "key"}), RespArray(ElementsAre()));
}
@ -858,8 +860,10 @@ TEST_F(GenericFamilyTest, FieldExpireHset) {
for (int i = 0; i < 3; ++i) {
EXPECT_EQ(CheckedInt({"HSET", "key", absl::StrCat("k", i), "v"}), 1);
}
AdvanceTime(2'000);
EXPECT_THAT(Run({"FIELDEXPIRE", "key", "10", "k0", "k1", "k2"}),
RespArray(ElementsAre(IntArg(1), IntArg(1), IntArg(1))));
EXPECT_EQ(10, CheckedInt({"fieldttl", "key", "k0"}));
AdvanceTime(10'000);
EXPECT_THAT(Run({"HGETALL", "key"}), RespArray(ElementsAre()));
}

View file

@ -1567,7 +1567,9 @@ vector<long> SetFamily::SetFieldsExpireTime(const OpArgs& op_args, uint32_t ttl_
pv->InitRobj(OBJ_SET, kEncodingStrMap2, ss);
}
return ExpireElements((StringSet*)pv->RObjPtr(), values, ttl_sec);
auto ss = static_cast<StringSet*>(pv->RObjPtr());
ss->set_time(MemberTimeSeconds(op_args.db_cntx.time_now_ms));
return ExpireElements(ss, values, ttl_sec);
}
} // namespace dfly