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

Function incrDecrCommand

app/redis-6.2.6/src/t_string.c:579–615  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

577}
578
579void incrDecrCommand(client *c, long long incr) {
580 long long value, oldvalue;
581 robj *o, *new;
582
583 o = lookupKeyWrite(c->db,c->argv[1]);
584 if (checkType(c,o,OBJ_STRING)) return;
585 if (getLongLongFromObjectOrReply(c,o,&value,NULL) != C_OK) return;
586
587 oldvalue = value;
588 if ((incr < 0 && oldvalue < 0 && incr < (LLONG_MIN-oldvalue)) ||
589 (incr > 0 && oldvalue > 0 && incr > (LLONG_MAX-oldvalue))) {
590 addReplyError(c,"increment or decrement would overflow");
591 return;
592 }
593 value += incr;
594
595 if (o && o->refcount == 1 && o->encoding == OBJ_ENCODING_INT &&
596 (value < 0 || value >= OBJ_SHARED_INTEGERS) &&
597 value >= LONG_MIN && value <= LONG_MAX)
598 {
599 new = o;
600 o->ptr = (void*)((long)value);
601 } else {
602 new = createStringObjectFromLongLongForValue(value);
603 if (o) {
604 dbOverwrite(c->db,c->argv[1],new);
605 } else {
606 dbAdd(c->db,c->argv[1],new);
607 }
608 }
609 signalModifiedKey(c,c->db,c->argv[1]);
610 notifyKeyspaceEvent(NOTIFY_STRING,"incrby",c->argv[1],c->db->id);
611 server.dirty++;
612 addReply(c,shared.colon);
613 addReply(c,new);
614 addReply(c,shared.crlf);
615}
616
617void incrCommand(client *c) {
618 incrDecrCommand(c,1);

Callers 4

incrCommandFunction · 0.85
decrCommandFunction · 0.85
incrbyCommandFunction · 0.85
decrbyCommandFunction · 0.85

Calls 10

lookupKeyWriteFunction · 0.85
checkTypeFunction · 0.85
addReplyErrorFunction · 0.85
dbOverwriteFunction · 0.85
dbAddFunction · 0.85
signalModifiedKeyFunction · 0.85
notifyKeyspaceEventFunction · 0.85
addReplyFunction · 0.85

Tested by

no test coverage detected