MCPcopy Create free account
hub / github.com/F-Stack/f-stack / renameGenericCommand

Function renameGenericCommand

app/redis-6.2.6/src/db.c:1090–1130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1088}
1089
1090void renameGenericCommand(client *c, int nx) {
1091 robj *o;
1092 long long expire;
1093 int samekey = 0;
1094
1095 /* When source and dest key is the same, no operation is performed,
1096 * if the key exists, however we still return an error on unexisting key. */
1097 if (sdscmp(c->argv[1]->ptr,c->argv[2]->ptr) == 0) samekey = 1;
1098
1099 if ((o = lookupKeyWriteOrReply(c,c->argv[1],shared.nokeyerr)) == NULL)
1100 return;
1101
1102 if (samekey) {
1103 addReply(c,nx ? shared.czero : shared.ok);
1104 return;
1105 }
1106
1107 incrRefCount(o);
1108 expire = getExpire(c->db,c->argv[1]);
1109 if (lookupKeyWrite(c->db,c->argv[2]) != NULL) {
1110 if (nx) {
1111 decrRefCount(o);
1112 addReply(c,shared.czero);
1113 return;
1114 }
1115 /* Overwrite: delete the old key before creating the new one
1116 * with the same name. */
1117 dbDelete(c->db,c->argv[2]);
1118 }
1119 dbAdd(c->db,c->argv[2],o);
1120 if (expire != -1) setExpire(c,c->db,c->argv[2],expire);
1121 dbDelete(c->db,c->argv[1]);
1122 signalModifiedKey(c,c->db,c->argv[1]);
1123 signalModifiedKey(c,c->db,c->argv[2]);
1124 notifyKeyspaceEvent(NOTIFY_GENERIC,"rename_from",
1125 c->argv[1],c->db->id);
1126 notifyKeyspaceEvent(NOTIFY_GENERIC,"rename_to",
1127 c->argv[2],c->db->id);
1128 server.dirty++;
1129 addReply(c,nx ? shared.cone : shared.ok);
1130}
1131
1132void renameCommand(client *c) {
1133 renameGenericCommand(c,0);

Callers 2

renameCommandFunction · 0.85
renamenxCommandFunction · 0.85

Calls 12

sdscmpFunction · 0.85
lookupKeyWriteOrReplyFunction · 0.85
addReplyFunction · 0.85
incrRefCountFunction · 0.85
getExpireFunction · 0.85
lookupKeyWriteFunction · 0.85
decrRefCountFunction · 0.85
dbDeleteFunction · 0.85
dbAddFunction · 0.85
setExpireFunction · 0.85
signalModifiedKeyFunction · 0.85
notifyKeyspaceEventFunction · 0.85

Tested by

no test coverage detected