diff --git a/src/server.cpp b/src/server.cpp index c1966f968..10048519f 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1042,6 +1042,10 @@ struct redisCommand redisCommandTable[] = { {"keydb.cron",cronCommand,-5, "write use-memory", 0,NULL,1,1,1,0,0,0}, + + {"keydb.hrename", hrenameCommand, 4, + "write fast @hash", + 0,NULL,0,0,0,0,0,0} }; /*============================ Utility functions ============================ */ diff --git a/src/server.h b/src/server.h index 9d13311e2..85da1fe9b 100644 --- a/src/server.h +++ b/src/server.h @@ -2966,6 +2966,7 @@ void xdelCommand(client *c); void xtrimCommand(client *c); void aclCommand(client *c); void replicaReplayCommand(client *c); +void hrenameCommand(client *c); int FBrokenLinkToMaster(); int FActiveMaster(client *c); diff --git a/src/t_hash.cpp b/src/t_hash.cpp index 25bb3b2e5..f1d893de6 100644 --- a/src/t_hash.cpp +++ b/src/t_hash.cpp @@ -832,3 +832,33 @@ void hscanCommand(client *c) { checkType(c,o,OBJ_HASH)) return; scanGenericCommand(c,o,cursor); } + +void hrenameCommand(client *c) { + robj *o = nullptr; + const unsigned char *vstr; + unsigned int vlen; + long long ll; + + if ((o = lookupKeyWriteOrReply(c,c->argv[1],shared.null[c->resp])) == nullptr || + checkType(c,o,OBJ_HASH)) return; + + if (hashTypeGetValue(o, szFromObj(c->argv[2]), &vstr, &vlen, &ll) != C_OK) + { + addReplyError(c, "hash key doesn't exist"); + return; + } + + sds sdsT = nullptr; + if (vstr != nullptr) + { + sdsT = sdsnewlen(vstr, vlen); + } + else + { + sdsT = sdsfromlonglong(ll); + } + + hashTypeDelete(o, szFromObj(c->argv[2])); + hashTypeSet(o, szFromObj(c->argv[3]), sdsT, HASH_SET_TAKE_VALUE); + addReplyLongLong(c, 1); +} \ No newline at end of file