mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 18:35:46 +02:00
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:
parent
39a00806c9
commit
ea17fc9893
2 changed files with 7 additions and 1 deletions
|
@ -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()));
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue