diff options
author | Pieter Noordhuis <pcnoordhuis@gmail.com> | 2011-04-03 17:46:59 +0200 |
---|---|---|
committer | Pieter Noordhuis <pcnoordhuis@gmail.com> | 2011-04-03 17:46:59 +0200 |
commit | 921150fc8a94276cb9a8d76d80f82a5872e29139 (patch) | |
tree | 2cef6df0be286c8fe3b70bf2075813e7d71a06c9 | |
parent | b4f85484eac7d469ec332045b7a28b0639ab468b (diff) |
Individual reply object functions may be NULL
-rw-r--r-- | hiredis.c | 39 |
1 files changed, 25 insertions, 14 deletions
@@ -271,14 +271,17 @@ static int processLineItem(redisReader *r) { int len; if ((p = readLine(r,&len)) != NULL) { - if (r->fn) { - if (cur->type == REDIS_REPLY_INTEGER) { + if (cur->type == REDIS_REPLY_INTEGER) { + if (r->fn && r->fn->createInteger) obj = r->fn->createInteger(cur,readLongLong(p)); - } else { - obj = r->fn->createString(cur,p,len); - } + else + obj = (void*)REDIS_REPLY_INTEGER; } else { - obj = (void*)(size_t)(cur->type); + /* Type will be error or status. */ + if (r->fn && r->fn->createString) + obj = r->fn->createString(cur,p,len); + else + obj = (void*)(size_t)(cur->type); } /* Set reply if this is the root object. */ @@ -306,15 +309,19 @@ static int processBulkItem(redisReader *r) { if (len < 0) { /* The nil object can always be created. */ - obj = r->fn ? r->fn->createNil(cur) : - (void*)REDIS_REPLY_NIL; + if (r->fn && r->fn->createNil) + obj = r->fn->createNil(cur); + else + obj = (void*)REDIS_REPLY_NIL; success = 1; } else { /* Only continue when the buffer contains the entire bulk item. */ bytelen += len+2; /* include \r\n */ if (r->pos+bytelen <= r->len) { - obj = r->fn ? r->fn->createString(cur,s+2,len) : - (void*)REDIS_REPLY_STRING; + if (r->fn && r->fn->createString) + obj = r->fn->createString(cur,s+2,len); + else + obj = (void*)REDIS_REPLY_STRING; success = 1; } } @@ -351,12 +358,16 @@ static int processMultiBulkItem(redisReader *r) { root = (r->ridx == 0); if (elements == -1) { - obj = r->fn ? r->fn->createNil(cur) : - (void*)REDIS_REPLY_NIL; + if (r->fn && r->fn->createNil) + obj = r->fn->createNil(cur); + else + obj = (void*)REDIS_REPLY_NIL; moveToNextTask(r); } else { - obj = r->fn ? r->fn->createArray(cur,elements) : - (void*)REDIS_REPLY_ARRAY; + if (r->fn && r->fn->createArray) + obj = r->fn->createArray(cur,elements); + else + obj = (void*)REDIS_REPLY_ARRAY; /* Modify task stack when there are more than 0 elements. */ if (elements > 0) { |