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

Function incrbyfloatCommand

src/t_string.cpp:643–674  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

641}
642
643void incrbyfloatCommand(client *c) {
644 long double incr, value;
645 robj *o, *newObj;
646
647 o = lookupKeyWrite(c->db,c->argv[1]);
648 if (checkType(c,o,OBJ_STRING)) return;
649 if (getLongDoubleFromObjectOrReply(c,o,&value,NULL) != C_OK ||
650 getLongDoubleFromObjectOrReply(c,c->argv[2],&incr,NULL) != C_OK)
651 return;
652
653 value += incr;
654 if (std::isnan(value) || std::isinf(value)) {
655 addReplyError(c,"increment would produce NaN or Infinity");
656 return;
657 }
658 newObj = createStringObjectFromLongDouble(value,1);
659 if (o)
660 dbOverwrite(c->db,c->argv[1],newObj);
661 else
662 dbAdd(c->db,c->argv[1],newObj);
663 signalModifiedKey(c,c->db,c->argv[1]);
664 notifyKeyspaceEvent(NOTIFY_STRING,"incrbyfloat",c->argv[1],c->db->id);
665 g_pserver->dirty++;
666 addReplyBulk(c,newObj);
667
668 /* Always replicate INCRBYFLOAT as a SET command with the final value
669 * in order to make sure that differences in float precision or formatting
670 * will not create differences in replicas or after an AOF restart. */
671 rewriteClientCommandArgument(c,0,shared.set);
672 rewriteClientCommandArgument(c,2,newObj);
673 rewriteClientCommandArgument(c,3,shared.keepttl);
674}
675
676void appendCommand(client *c) {
677 size_t totlen;

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected