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

Function hincrbyCommand

src/t_hash.cpp:688–721  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

686}
687
688void hincrbyCommand(client *c) {
689 long long value, incr, oldvalue;
690 robj *o;
691 sds newstr;
692 const unsigned char *vstr;
693 unsigned int vlen;
694
695 if (getLongLongFromObjectOrReply(c,c->argv[3],&incr,NULL) != C_OK) return;
696 if ((o = hashTypeLookupWriteOrCreate(c,c->argv[1])) == NULL) return;
697 if (hashTypeGetValue(o,szFromObj(c->argv[2]),&vstr,&vlen,&value) == C_OK) {
698 if (vstr) {
699 if (string2ll((char*)vstr,vlen,&value) == 0) {
700 addReplyError(c,"hash value is not an integer");
701 return;
702 }
703 } /* Else hashTypeGetValue() already stored it into &value */
704 } else {
705 value = 0;
706 }
707
708 oldvalue = value;
709 if ((incr < 0 && oldvalue < 0 && incr < (LLONG_MIN-oldvalue)) ||
710 (incr > 0 && oldvalue > 0 && incr > (LLONG_MAX-oldvalue))) {
711 addReplyError(c,"increment or decrement would overflow");
712 return;
713 }
714 value += incr;
715 newstr = sdsfromlonglong(value);
716 hashTypeSet(o,szFromObj(c->argv[2]),newstr,HASH_SET_TAKE_VALUE);
717 addReplyLongLong(c,value);
718 signalModifiedKey(c,c->db,c->argv[1]);
719 notifyKeyspaceEvent(NOTIFY_HASH,"hincrby",c->argv[1],c->db->id);
720 g_pserver->dirty++;
721}
722
723void hincrbyfloatCommand(client *c) {
724 long double value, incr;

Callers

nothing calls this directly

Calls 11

hashTypeGetValueFunction · 0.85
szFromObjFunction · 0.85
addReplyErrorFunction · 0.85
sdsfromlonglongFunction · 0.85
hashTypeSetFunction · 0.85
addReplyLongLongFunction · 0.85
signalModifiedKeyFunction · 0.85
notifyKeyspaceEventFunction · 0.85
string2llFunction · 0.70

Tested by

no test coverage detected