feat(server): implement TOUCH command (#444)

Signed-off-by: Leonardo Mello <lsvmello@gmail.com>

Signed-off-by: Leonardo Mello <lsvmello@gmail.com>
This commit is contained in:
Leonardo Mello 2022-10-31 16:07:13 -03:00 committed by GitHub
parent becc0f38c0
commit efd307dbb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 3 deletions

View File

@ -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)**

View File

@ -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

View File

@ -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)

View File

@ -32,7 +32,6 @@ class GenericFamily {
static OpResult<uint32_t> 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);

View File

@ -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');