diff --git a/src/redis.c b/src/redis.c index a6d1b577203048b860549b9275854455da8ab9c3..606ac978ee94a27f23cb285be046e0ea781aeb0d 100644 --- a/src/redis.c +++ b/src/redis.c @@ -157,6 +157,7 @@ struct redisCommand redisCommandTable[] = { {"hmset",hmsetCommand,-4,"wm",0,NULL,1,1,1,0,0}, {"hmget",hmgetCommand,-3,"r",0,NULL,1,1,1,0,0}, {"hincrby",hincrbyCommand,4,"wm",0,NULL,1,1,1,0,0}, + {"hincrbyfloat",hincrbyfloatCommand,4,"wm",0,NULL,1,1,1,0,0}, {"hdel",hdelCommand,-3,"w",0,NULL,1,1,1,0,0}, {"hlen",hlenCommand,2,"r",0,NULL,1,1,1,0,0}, {"hkeys",hkeysCommand,2,"r",0,NULL,1,1,1,0,0}, diff --git a/src/redis.h b/src/redis.h index 3d1e81aa9845b5e8d8365d0d64c7a1b27106ecf7..0330db74e670cc73e38b2f6210fae06784c6082e 100644 --- a/src/redis.h +++ b/src/redis.h @@ -1104,6 +1104,7 @@ void hgetallCommand(redisClient *c); void hexistsCommand(redisClient *c); void configCommand(redisClient *c); void hincrbyCommand(redisClient *c); +void hincrbyfloatCommand(redisClient *c); void subscribeCommand(redisClient *c); void unsubscribeCommand(redisClient *c); void psubscribeCommand(redisClient *c); diff --git a/src/t_hash.c b/src/t_hash.c index eebb66f3638bc395aa42e2352b5fcd01319baf5d..8ee5485c1ad86f877d6f24e6bce98ca461f7f172 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;