MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / appendCommand

Function appendCommand

src/t_string.cpp:676–706  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

674}
675
676void appendCommand(client *c) {
677 size_t totlen;
678 robj *o, *append;
679
680 o = lookupKeyWrite(c->db,c->argv[1]);
681 if (o == NULL) {
682 /* Create the key */
683 c->argv[2] = tryObjectEncoding(c->argv[2]);
684 dbAdd(c->db,c->argv[1],c->argv[2]);
685 incrRefCount(c->argv[2]);
686 totlen = stringObjectLen(c->argv[2]);
687 } else {
688 /* Key exists, check type */
689 if (checkType(c,o,OBJ_STRING))
690 return;
691
692 /* "append" is an argument, so always an sds */
693 append = c->argv[2];
694 if (checkStringLength(c,stringObjectLen(o),sdslen((sds)ptrFromObj(append))) != C_OK)
695 return;
696
697 /* Append the value */
698 o = dbUnshareStringValue(c->db,c->argv[1],o);
699 o->m_ptr = sdscatlen((sds)ptrFromObj(o),ptrFromObj(append),sdslen((sds)ptrFromObj(append)));
700 totlen = sdslen((sds)ptrFromObj(o));
701 }
702 signalModifiedKey(c,c->db,c->argv[1]);
703 notifyKeyspaceEvent(NOTIFY_STRING,"append",c->argv[1],c->db->id);
704 g_pserver->dirty++;
705 addReplyLongLong(c,totlen);
706}
707
708void strlenCommand(client *c) {
709 robj_roptr o;

Callers

nothing calls this directly

Calls 14

lookupKeyWriteFunction · 0.85
tryObjectEncodingFunction · 0.85
dbAddFunction · 0.85
incrRefCountFunction · 0.85
stringObjectLenFunction · 0.85
checkTypeFunction · 0.85
checkStringLengthFunction · 0.85
sdslenFunction · 0.85
ptrFromObjFunction · 0.85
dbUnshareStringValueFunction · 0.85
sdscatlenFunction · 0.85
signalModifiedKeyFunction · 0.85

Tested by

no test coverage detected