diff --git a/src/core/interpreter.cc b/src/core/interpreter.cc index 540e4542b..f8c6db6ad 100644 --- a/src/core/interpreter.cc +++ b/src/core/interpreter.cc @@ -895,4 +895,11 @@ void InterpreterManager::Return(Interpreter* ir) { waker_.notify(); } +void InterpreterManager::Reset() { + waker_.await([this]() { return available_.size() == storage_.size(); }); + + available_.clear(); + storage_.clear(); +} + } // namespace dfly diff --git a/src/core/interpreter.h b/src/core/interpreter.h index 91f1479a8..b550710ff 100644 --- a/src/core/interpreter.h +++ b/src/core/interpreter.h @@ -149,6 +149,8 @@ class InterpreterManager { void Return(Interpreter*); + void Reset(); + private: EventCount waker_; std::vector available_; diff --git a/src/server/dragonfly_test.cc b/src/server/dragonfly_test.cc index 7da960851..8d388d84b 100644 --- a/src/server/dragonfly_test.cc +++ b/src/server/dragonfly_test.cc @@ -256,6 +256,29 @@ TEST_F(DflyEngineTest, EvalSha) { EXPECT_THAT(resp, "c6459b95a0e81df97af6fdd49b1a9e0287a57363"); } +TEST_F(DflyEngineTest, ScriptFlush) { + auto resp = Run({"script", "load", "return 5"}); + EXPECT_THAT(resp, ArgType(RespExpr::STRING)); + string sha{ToSV(resp.GetBuf())}; + resp = Run({"evalsha", sha, "0"}); + EXPECT_THAT(5, resp.GetInt()); + resp = Run({"script", "exists", sha}); + EXPECT_THAT(1, resp.GetInt()); + + resp = Run({"script", "flush"}); + resp = Run({"script", "exists", sha}); + EXPECT_THAT(0, resp.GetInt()); + EXPECT_THAT(Run({"evalsha", sha, "0"}), ErrArg("NOSCRIPT No matching script. Please use EVAL.")); + + resp = Run({"script", "load", "return 5"}); + EXPECT_THAT(resp, ArgType(RespExpr::STRING)); + sha = string{ToSV(resp.GetBuf())}; + resp = Run({"evalsha", sha, "0"}); + EXPECT_THAT(5, resp.GetInt()); + resp = Run({"script", "exists", sha}); + EXPECT_THAT(1, resp.GetInt()); +} + TEST_F(DflyEngineTest, Hello) { auto resp = Run({"hello"}); ASSERT_THAT(resp, ArrLen(14)); diff --git a/src/server/script_mgr.cc b/src/server/script_mgr.cc index 8bfc41f43..fe30f928e 100644 --- a/src/server/script_mgr.cc +++ b/src/server/script_mgr.cc @@ -63,6 +63,8 @@ void ScriptMgr::Run(CmdArgList args, ConnectionContext* cntx) { "Subcommands are:", "EXISTS [ ...]", " Return information about the existence of the scripts in the script cache.", + "FLUSH", + " Flush the Lua scripts cache. Very dangerous on replicas.", "LOAD