X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/d4a3cfed9c95e0ca5f8bcc771f8844ad17895c69..68bfe993c8aa0d43bb2a5cf02b5d325effb67b0c:/src/t_hash.c diff --git a/src/t_hash.c b/src/t_hash.c index eebb66f3..8ee5485c 100644 --- a/src/t_hash.c +++ b/src/t_hash.c @@ -346,6 +346,33 @@ void hincrbyCommand(redisClient *c) { server.dirty++; } +void hincrbyfloatCommand(redisClient *c) { + double long value, incr; + robj *o, *current, *new; + + if (getLongDoubleFromObjectOrReply(c,c->argv[3],&incr,NULL) != REDIS_OK) return; + if ((o = hashTypeLookupWriteOrCreate(c,c->argv[1])) == NULL) return; + if ((current = hashTypeGetObject(o,c->argv[2])) != NULL) { + if (getLongDoubleFromObjectOrReply(c,current,&value, + "hash value is not a valid float") != REDIS_OK) { + decrRefCount(current); + return; + } + decrRefCount(current); + } else { + value = 0; + } + + value += incr; + new = createStringObjectFromLongDouble(value); + hashTypeTryObjectEncoding(o,&c->argv[2],NULL); + hashTypeSet(o,c->argv[2],new); + addReplyBulk(c,new); + decrRefCount(new); + signalModifiedKey(c->db,c->argv[1]); + server.dirty++; +} + void hgetCommand(redisClient *c) { robj *o, *value; unsigned char *v;