fix: RENAMENX according to spec #226 Signed-off-by: odedponcz <oded@poncz.com>
This commit is contained in:
parent
d19fa58216
commit
3b04801cd6
|
@ -443,7 +443,14 @@ void GenericFamily::Rename(CmdArgList args, ConnectionContext* cntx) {
|
|||
|
||||
void GenericFamily::RenameNx(CmdArgList args, ConnectionContext* cntx) {
|
||||
OpResult<void> st = RenameGeneric(args, true, cntx);
|
||||
(*cntx)->SendError(st.status());
|
||||
OpStatus status = st.status();
|
||||
if (status == OpStatus::OK) {
|
||||
(*cntx)->SendLong(1);
|
||||
} else if (status == OpStatus::KEY_EXISTS) {
|
||||
(*cntx)->SendLong(0);
|
||||
} else {
|
||||
(*cntx)->SendError(status);
|
||||
}
|
||||
}
|
||||
|
||||
void GenericFamily::Ttl(CmdArgList args, ConnectionContext* cntx) {
|
||||
|
|
|
@ -153,6 +153,19 @@ TEST_F(GenericFamilyTest, RenameBinary) {
|
|||
EXPECT_EQ(Run({"get", kKey2}), "bar");
|
||||
}
|
||||
|
||||
TEST_F(GenericFamilyTest, RenameNx) {
|
||||
// Set two keys
|
||||
string b_val(32, 'b');
|
||||
string x_val(32, 'x');
|
||||
Run({"mset", "x", x_val, "b", b_val});
|
||||
|
||||
ASSERT_THAT(Run({"renamenx", "z", "b"}), ErrArg("no such key"));
|
||||
ASSERT_THAT(Run({"renamenx", "x", "b"}), IntArg(0)); // b already exists
|
||||
ASSERT_THAT(Run({"renamenx", "x", "y"}), IntArg(1));
|
||||
ASSERT_EQ(Run({"get", "y"}), x_val);
|
||||
}
|
||||
|
||||
|
||||
using testing::AnyOf;
|
||||
using testing::Each;
|
||||
using testing::StartsWith;
|
||||
|
|
Loading…
Reference in New Issue