From efd307dbb95a06b2ad0f1852adeb04c827f8ab3e Mon Sep 17 00:00:00 2001 From: Leonardo Mello Date: Mon, 31 Oct 2022 16:07:13 -0300 Subject: [PATCH] feat(server): implement TOUCH command (#444) Signed-off-by: Leonardo Mello Signed-off-by: Leonardo Mello --- CONTRIBUTORS.md | 1 + docs/api_status.md | 4 ++-- src/server/generic_family.cc | 1 + src/server/generic_family.h | 1 - src/server/generic_family_test.cc | 11 +++++++++++ 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 6e5a6ce3c..af3c42997 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -13,3 +13,4 @@ * **[Ali-Akber Saifee](https://github.com/alisaifee)** * **[Elle Y](https://github.com/inohime)** * **[ATM SALEH](https://github.com/ATM-SALEH)** +* **[Leonardo Mello](https://github.com/lsvmello)** diff --git a/docs/api_status.md b/docs/api_status.md index ff67265fe..276aaa83d 100644 --- a/docs/api_status.md +++ b/docs/api_status.md @@ -202,8 +202,8 @@ with respect to Memcached and Redis APIs. - [ ] PFMERGE ### API 3 -- [ ] Generic Family - - [ ] TOUCH +- [X] Generic Family + - [X] TOUCH - [X] HashSet Family - [X] HSTRLEN - [X] Server Family diff --git a/src/server/generic_family.cc b/src/server/generic_family.cc index a1b952745..d7af80fa9 100644 --- a/src/server/generic_family.cc +++ b/src/server/generic_family.cc @@ -1405,6 +1405,7 @@ void GenericFamily::Register(CommandRegistry* registry) { << CI{"PING", CO::FAST, -1, 0, 0, 0}.HFUNC(Ping) << CI{"ECHO", CO::LOADING | CO::FAST, 2, 0, 0, 0}.HFUNC(Echo) << CI{"EXISTS", CO::READONLY | CO::FAST, -2, 1, -1, 1}.HFUNC(Exists) + << CI{"TOUCH", CO::READONLY | CO::FAST, -2, 1, -1, 1}.HFUNC(Exists) << CI{"EXPIRE", CO::WRITE | CO::FAST, 3, 1, 1, 1}.HFUNC(Expire) << CI{"EXPIREAT", CO::WRITE | CO::FAST, 3, 1, 1, 1}.HFUNC(ExpireAt) << CI{"PERSIST", CO::WRITE | CO::FAST, 2, 1, 1, 1}.HFUNC(Persist) diff --git a/src/server/generic_family.h b/src/server/generic_family.h index ce63bd8fa..0ebc7ca54 100644 --- a/src/server/generic_family.h +++ b/src/server/generic_family.h @@ -32,7 +32,6 @@ class GenericFamily { static OpResult OpExists(const OpArgs& op_args, ArgSlice keys); private: - static void Del(CmdArgList args, ConnectionContext* cntx); static void Ping(CmdArgList args, ConnectionContext* cntx); static void Exists(CmdArgList args, ConnectionContext* cntx); diff --git a/src/server/generic_family_test.cc b/src/server/generic_family_test.cc index 11d2b3ce0..2a1fc3e01 100644 --- a/src/server/generic_family_test.cc +++ b/src/server/generic_family_test.cc @@ -94,6 +94,17 @@ TEST_F(GenericFamilyTest, Exists) { EXPECT_THAT(resp, IntArg(3)); } +TEST_F(GenericFamilyTest, Touch) { + RespExpr resp; + + Run({"mset", "x", "0", "y", "1"}); + resp = Run({"touch", "x", "y", "x"}); + EXPECT_THAT(resp, IntArg(3)); + + resp = Run({"touch", "z", "x", "w"}); + EXPECT_THAT(resp, IntArg(1)); +} + TEST_F(GenericFamilyTest, Rename) { RespExpr resp; string b_val(32, 'b');