1
0
Fork 0
mirror of https://github.com/dragonflydb/dragonfly.git synced 2024-12-14 11:58:02 +00:00

feat(server family): reject flushall and flushdb on multi command (#657)

* feat(server family): reject flushall and flushdb on multi command

Signed-off-by: adi_holden <adi@dragonflydb.io>
This commit is contained in:
adiholden 2023-01-09 12:00:15 +02:00 committed by GitHub
parent 1fa5340c27
commit 53f3d860db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View file

@ -101,6 +101,16 @@ TEST_F(DflyEngineTest, MultiAndEval) {
"transaction block"));
}
TEST_F(DflyEngineTest, MultiAndFlush) {
RespExpr resp = Run({"multi"});
ASSERT_EQ(resp, "OK");
resp = Run({"get", kKey1});
ASSERT_EQ(resp, "QUEUED");
EXPECT_THAT(Run({"FLUSHALL"}), ErrArg("'FLUSHALL' inside MULTI is not allowed"));
}
TEST_F(DflyEngineTest, Multi) {
RespExpr resp = Run({"multi"});
ASSERT_EQ(resp, "OK");
@ -650,7 +660,7 @@ TEST_F(DflyEngineTest, Watch) {
// Check watch doesn't run in multi.
Run({"multi"});
ASSERT_THAT(Run({"watch", "a"}), ErrArg("WATCH inside MULTI is not allowed"));
ASSERT_THAT(Run({"watch", "a"}), ErrArg("'WATCH' inside MULTI is not allowed"));
Run({"discard"});
// Check watch on existing key.

View file

@ -606,9 +606,9 @@ void Service::DispatchCommand(CmdArgList args, facade::ConnectionContext* cntx)
return;
}
if (cmd_name == "WATCH") {
(*cntx)->SendError("WATCH inside MULTI is not allowed");
return;
if (cmd_name == "WATCH" || cmd_name == "FLUSHALL" || cmd_name == "FLUSHDB") {
auto error = absl::StrCat("'", cmd_name, "' inside MULTI is not allowed");
return (*cntx)->SendError(error);
}
}