diff --git a/src/config.cc b/src/config.cc index 4151620cb39..2dae8aa8c7b 100644 --- a/src/config.cc +++ b/src/config.cc @@ -742,6 +742,9 @@ Status Config::AddNamespace(const std::string &ns, const std::string &token) { if (cluster_enabled) { return Status(Status::NotOK, "forbidden to add namespace when cluster mode was enabled"); } + if (ns == kDefaultNamespace) { + return Status(Status::NotOK, "forbidden to add the default namespace"); + } auto s = isNamespaceLegal(ns); if (!s.IsOK()) return s; if (tokens.find(token) != tokens.end()) { diff --git a/src/redis_cmd.cc b/src/redis_cmd.cc index 62ee1025b60..7cae0cb979a 100644 --- a/src/redis_cmd.cc +++ b/src/redis_cmd.cc @@ -112,6 +112,8 @@ class CommandNamespace : public Commander { namespaces.emplace_back(iter->second); // namespace namespaces.emplace_back(iter->first); // token } + namespaces.emplace_back(kDefaultNamespace); + namespaces.emplace_back(config->requirepass); *output = Redis::MultiBulkString(namespaces, false); } else { std::string token; diff --git a/tests/cppunit/config_test.cc b/tests/cppunit/config_test.cc index 74f31a77772..7efc0564e14 100644 --- a/tests/cppunit/config_test.cc +++ b/tests/cppunit/config_test.cc @@ -179,6 +179,10 @@ TEST(Namespace, Add) { auto s = config.AddNamespace("n1", "t0"); EXPECT_FALSE(s.IsOK()); EXPECT_EQ(s.Msg(), "the namespace has already exists"); + + s = config.AddNamespace(kDefaultNamespace, "mytoken"); + EXPECT_FALSE(s.IsOK()); + EXPECT_EQ(s.Msg(), "forbidden to add the default namespace"); unlink(path); }