mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2024-12-14 11:58:02 +00:00
fix(server):Return an error, instead of crashing, for requests trying to rename a key to the same key. (#897)
fix:Return an error, instead of crashing, for requests trying to rename a key to the same key. Fixes #850 --------- Co-authored-by: Shahar Mike <shmike@google.com>
This commit is contained in:
parent
4a5d2f2a9a
commit
bcc3d3ec4f
3 changed files with 13 additions and 2 deletions
|
@ -13,7 +13,6 @@ std::string WrongNumArgsError(std::string_view cmd);
|
|||
std::string InvalidExpireTime(std::string_view cmd);
|
||||
std::string UnknownSubCmd(std::string_view subcmd, std::string_view cmd);
|
||||
|
||||
|
||||
extern const char kSyntaxErr[];
|
||||
extern const char kWrongTypeErr[];
|
||||
extern const char kKeyNotFoundErr[];
|
||||
|
@ -32,4 +31,4 @@ extern const char kIndexOutOfRange[];
|
|||
extern const char kOutOfMemory[];
|
||||
extern const char kInvalidNumericResult[];
|
||||
|
||||
} // namespace dfly
|
||||
} // namespace facade
|
||||
|
|
|
@ -1327,6 +1327,9 @@ OpResult<void> GenericFamily::OpRen(const OpArgs& op_args, string_view from_key,
|
|||
if (!IsValid(from_it))
|
||||
return OpStatus::KEY_NOTFOUND;
|
||||
|
||||
if (from_key == to_key)
|
||||
return OpStatus::OK;
|
||||
|
||||
bool is_prior_list = false;
|
||||
auto [to_it, to_expire] = db_slice.FindExt(op_args.db_cntx, to_key);
|
||||
if (IsValid(to_it)) {
|
||||
|
|
|
@ -199,6 +199,15 @@ TEST_F(GenericFamilyTest, RenameNx) {
|
|||
ASSERT_EQ(Run({"get", "y"}), x_val);
|
||||
}
|
||||
|
||||
TEST_F(GenericFamilyTest, RenameSameName) {
|
||||
const char kKey[] = "key";
|
||||
|
||||
ASSERT_THAT(Run({"rename", kKey, kKey}), ErrArg("no such key"));
|
||||
|
||||
ASSERT_EQ(Run({"set", kKey, "value"}), "OK");
|
||||
EXPECT_EQ(Run({"rename", kKey, kKey}), "OK");
|
||||
}
|
||||
|
||||
TEST_F(GenericFamilyTest, Stick) {
|
||||
// check stick returns zero on non-existent keys
|
||||
ASSERT_THAT(Run({"stick", "a", "b"}), IntArg(0));
|
||||
|
|
Loading…
Reference in a new issue