X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/eab0e26e03fa3c27a4e1172659cea32e1b83699e..ad0df18fdc965183533515aae5e4e01009616c86:/src/t_hash.c?ds=sidebyside diff --git a/src/t_hash.c b/src/t_hash.c index 3ccdfd14..b8e2ad31 100644 --- a/src/t_hash.c +++ b/src/t_hash.c @@ -55,7 +55,7 @@ int hashTypeGet(robj *o, robj *key, robj **objval, unsigned char **v, } else { dictEntry *de = dictFind(o->ptr,key); if (de == NULL) return -1; - *objval = dictGetEntryVal(de); + *objval = dictGetVal(de); } return o->encoding; } @@ -206,9 +206,9 @@ int hashTypeCurrent(hashTypeIterator *hi, int what, robj **objval, unsigned char } } else { if (what & REDIS_HASH_KEY) - *objval = dictGetEntryKey(hi->de); + *objval = dictGetKey(hi->de); else - *objval = dictGetEntryVal(hi->de); + *objval = dictGetVal(hi->de); } return hi->encoding; } @@ -320,7 +320,7 @@ void hmsetCommand(redisClient *c) { } void hincrbyCommand(redisClient *c) { - long long value, incr; + long long value, incr, oldvalue; robj *o, *current, *new; if (getLongLongFromObjectOrReply(c,c->argv[3],&incr,NULL) != REDIS_OK) return; @@ -336,7 +336,12 @@ void hincrbyCommand(redisClient *c) { value = 0; } + oldvalue = value; value += incr; + if ((incr < 0 && value > oldvalue) || (incr > 0 && value < oldvalue)) { + addReplyError(c,"increment or decrement would overflow"); + return; + } new = createStringObjectFromLongLong(value); hashTypeTryObjectEncoding(o,&c->argv[2],NULL); hashTypeSet(o,c->argv[2],new); @@ -346,6 +351,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;