mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 18:35:46 +02:00
Check for integer validity in setex command
This commit is contained in:
parent
affabbaee7
commit
f9b70125d6
4 changed files with 10 additions and 5 deletions
|
@ -172,12 +172,16 @@ void StringFamily::SetEx(CmdArgList args, ConnectionContext* cntx) {
|
|||
string_view key = ArgS(args, 1);
|
||||
string_view ex = ArgS(args, 2);
|
||||
string_view value = ArgS(args, 3);
|
||||
uint32_t secs;
|
||||
int32_t secs;
|
||||
|
||||
if (!absl::SimpleAtoi(ex, &secs)) {
|
||||
return (*cntx)->SendError(kInvalidIntErr);
|
||||
}
|
||||
|
||||
if (secs < 1) {
|
||||
return (*cntx)->SendError(absl::StrCat(facade::kInvalidExpireTime, " in setex"));
|
||||
}
|
||||
|
||||
SetCmd::SetParams sparams{cntx->db_index()};
|
||||
sparams.expire_after_ms = uint64_t(secs) * 1000;
|
||||
|
||||
|
|
|
@ -253,9 +253,10 @@ TEST_F(StringFamilyTest, MSetIncr) {
|
|||
}
|
||||
|
||||
TEST_F(StringFamilyTest, SetEx) {
|
||||
ASSERT_THAT(Run({"setex", "key", "1", "val"}), RespEq("OK"));
|
||||
ASSERT_THAT(Run({"setex", "key", "10", "val"}), RespEq("OK"));
|
||||
ASSERT_THAT(Run({"setex", "key", "10", "val"}), RespEq("OK"));
|
||||
ASSERT_THAT(Run({"setex", "key", "10", "val"}), RespEq("OK"));
|
||||
ASSERT_THAT(Run({"ttl", "key"}), ElementsAre(IntArg(10)));
|
||||
ASSERT_THAT(Run({"setex", "key", "0", "val"}), ElementsAre(ErrArg("invalid expire time")));
|
||||
}
|
||||
|
||||
} // namespace dfly
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue