RESP3: hiredis: implement bool type.
This commit is contained in:
parent
e291170385
commit
dfa9d2c74c
25
deps/hiredis/hiredis.c
vendored
25
deps/hiredis/hiredis.c
vendored
@ -49,6 +49,7 @@ static void *createArrayObject(const redisReadTask *task, int elements);
|
|||||||
static void *createIntegerObject(const redisReadTask *task, long long value);
|
static void *createIntegerObject(const redisReadTask *task, long long value);
|
||||||
static void *createDoubleObject(const redisReadTask *task, double value, char *str, size_t len);
|
static void *createDoubleObject(const redisReadTask *task, double value, char *str, size_t len);
|
||||||
static void *createNilObject(const redisReadTask *task);
|
static void *createNilObject(const redisReadTask *task);
|
||||||
|
static void *createBoolObject(const redisReadTask *task, int bval);
|
||||||
|
|
||||||
/* Default set of functions to build the reply. Keep in mind that such a
|
/* Default set of functions to build the reply. Keep in mind that such a
|
||||||
* function returning NULL is interpreted as OOM. */
|
* function returning NULL is interpreted as OOM. */
|
||||||
@ -58,6 +59,7 @@ static redisReplyObjectFunctions defaultFunctions = {
|
|||||||
createIntegerObject,
|
createIntegerObject,
|
||||||
createDoubleObject,
|
createDoubleObject,
|
||||||
createNilObject,
|
createNilObject,
|
||||||
|
createBoolObject,
|
||||||
freeReplyObject
|
freeReplyObject
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -223,7 +225,28 @@ static void *createNilObject(const redisReadTask *task) {
|
|||||||
|
|
||||||
if (task->parent) {
|
if (task->parent) {
|
||||||
parent = task->parent->obj;
|
parent = task->parent->obj;
|
||||||
assert(parent->type == REDIS_REPLY_ARRAY);
|
assert(parent->type == REDIS_REPLY_ARRAY ||
|
||||||
|
parent->type == REDIS_REPLY_MAP ||
|
||||||
|
parent->type == REDIS_REPLY_SET);
|
||||||
|
parent->element[task->idx] = r;
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *createBoolObject(const redisReadTask *task, int bval) {
|
||||||
|
redisReply *r, *parent;
|
||||||
|
|
||||||
|
r = createReplyObject(REDIS_REPLY_BOOL);
|
||||||
|
if (r == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
r->integer = bval != 0;
|
||||||
|
|
||||||
|
if (task->parent) {
|
||||||
|
parent = task->parent->obj;
|
||||||
|
assert(parent->type == REDIS_REPLY_ARRAY ||
|
||||||
|
parent->type == REDIS_REPLY_MAP ||
|
||||||
|
parent->type == REDIS_REPLY_SET);
|
||||||
parent->element[task->idx] = r;
|
parent->element[task->idx] = r;
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
|
10
deps/hiredis/read.c
vendored
10
deps/hiredis/read.c
vendored
@ -313,6 +313,12 @@ static int processLineItem(redisReader *r) {
|
|||||||
obj = r->fn->createNil(cur);
|
obj = r->fn->createNil(cur);
|
||||||
else
|
else
|
||||||
obj = (void*)REDIS_REPLY_NIL;
|
obj = (void*)REDIS_REPLY_NIL;
|
||||||
|
} else if (cur->type == REDIS_REPLY_BOOL) {
|
||||||
|
int bval = p[0] == 't' || p[0] == 'T';
|
||||||
|
if (r->fn && r->fn->createBool)
|
||||||
|
obj = r->fn->createBool(cur,bval);
|
||||||
|
else
|
||||||
|
obj = (void*)REDIS_REPLY_BOOL;
|
||||||
} else {
|
} else {
|
||||||
/* Type will be error or status. */
|
/* Type will be error or status. */
|
||||||
if (r->fn && r->fn->createString)
|
if (r->fn && r->fn->createString)
|
||||||
@ -513,6 +519,9 @@ static int processItem(redisReader *r) {
|
|||||||
case '~':
|
case '~':
|
||||||
cur->type = REDIS_REPLY_SET;
|
cur->type = REDIS_REPLY_SET;
|
||||||
break;
|
break;
|
||||||
|
case '#':
|
||||||
|
cur->type = REDIS_REPLY_BOOL;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
__redisReaderSetErrorProtocolByte(r,*p);
|
__redisReaderSetErrorProtocolByte(r,*p);
|
||||||
return REDIS_ERR;
|
return REDIS_ERR;
|
||||||
@ -530,6 +539,7 @@ static int processItem(redisReader *r) {
|
|||||||
case REDIS_REPLY_INTEGER:
|
case REDIS_REPLY_INTEGER:
|
||||||
case REDIS_REPLY_DOUBLE:
|
case REDIS_REPLY_DOUBLE:
|
||||||
case REDIS_REPLY_NIL:
|
case REDIS_REPLY_NIL:
|
||||||
|
case REDIS_REPLY_BOOL:
|
||||||
return processLineItem(r);
|
return processLineItem(r);
|
||||||
case REDIS_REPLY_STRING:
|
case REDIS_REPLY_STRING:
|
||||||
return processBulkItem(r);
|
return processBulkItem(r);
|
||||||
|
1
deps/hiredis/read.h
vendored
1
deps/hiredis/read.h
vendored
@ -83,6 +83,7 @@ typedef struct redisReplyObjectFunctions {
|
|||||||
void *(*createInteger)(const redisReadTask*, long long);
|
void *(*createInteger)(const redisReadTask*, long long);
|
||||||
void *(*createDouble)(const redisReadTask*, double, char*, size_t);
|
void *(*createDouble)(const redisReadTask*, double, char*, size_t);
|
||||||
void *(*createNil)(const redisReadTask*);
|
void *(*createNil)(const redisReadTask*);
|
||||||
|
void *(*createBool)(const redisReadTask*, int);
|
||||||
void (*freeObject)(void*);
|
void (*freeObject)(void*);
|
||||||
} redisReplyObjectFunctions;
|
} redisReplyObjectFunctions;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user