From 5e26ae88b8082090263281737f918b2a3ad71706 Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Mon, 5 Apr 2010 16:51:34 +0200 Subject: [PATCH 1/2] last argument is never encoded for HINCRBY --- redis.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/redis.c b/redis.c index 9e5bc94a..e4ddd99c 100644 --- a/redis.c +++ b/redis.c @@ -6037,10 +6037,7 @@ static void hincrbyCommand(redisClient *c) { } } - robj *o_incr = getDecodedObject(c->argv[3]); - incr = strtoll(o_incr->ptr, NULL, 10); - decrRefCount(o_incr); - + incr = strtoll(c->argv[3]->ptr, NULL, 10); if (o->encoding == REDIS_ENCODING_ZIPMAP) { unsigned char *zm = o->ptr; unsigned char *zval; From aa7c29340f87889467f343a8783bc9908df5483d Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Mon, 5 Apr 2010 16:51:48 +0200 Subject: [PATCH 2/2] use long long reply type for HINCRBY --- redis.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/redis.c b/redis.c index e4ddd99c..85244859 100644 --- a/redis.c +++ b/redis.c @@ -2601,6 +2601,21 @@ static void addReplyLong(redisClient *c, long l) { addReplySds(c,sdsnewlen(buf,len)); } +static void addReplyLongLong(redisClient *c, long long ll) { + char buf[128]; + size_t len; + + if (ll == 0) { + addReply(c,shared.czero); + return; + } else if (ll == 1) { + addReply(c,shared.cone); + return; + } + len = snprintf(buf,sizeof(buf),":%lld\r\n",ll); + addReplySds(c,sdsnewlen(buf,len)); +} + static void addReplyUlong(redisClient *c, unsigned long ul) { char buf[128]; size_t len; @@ -6088,7 +6103,7 @@ static void hincrbyCommand(redisClient *c) { } server.dirty++; - addReplyLong(c, value); + addReplyLongLong(c, value); } static void hgetCommand(redisClient *c) {