Commit 40eb548a authored by antirez's avatar antirez
Browse files

RDMF: REDIS_OK REDIS_ERR -> C_OK C_ERR.

parent 2d9e3eb1
...@@ -308,7 +308,7 @@ void lindexCommand(client *c) { ...@@ -308,7 +308,7 @@ void lindexCommand(client *c) {
long index; long index;
robj *value = NULL; robj *value = NULL;
if ((getLongFromObjectOrReply(c, c->argv[2], &index, NULL) != REDIS_OK)) if ((getLongFromObjectOrReply(c, c->argv[2], &index, NULL) != C_OK))
return; return;
if (o->encoding == OBJ_ENCODING_QUICKLIST) { if (o->encoding == OBJ_ENCODING_QUICKLIST) {
...@@ -335,7 +335,7 @@ void lsetCommand(client *c) { ...@@ -335,7 +335,7 @@ void lsetCommand(client *c) {
long index; long index;
robj *value = c->argv[3]; robj *value = c->argv[3];
if ((getLongFromObjectOrReply(c, c->argv[2], &index, NULL) != REDIS_OK)) if ((getLongFromObjectOrReply(c, c->argv[2], &index, NULL) != C_OK))
return; return;
if (o->encoding == OBJ_ENCODING_QUICKLIST) { if (o->encoding == OBJ_ENCODING_QUICKLIST) {
...@@ -390,8 +390,8 @@ void lrangeCommand(client *c) { ...@@ -390,8 +390,8 @@ void lrangeCommand(client *c) {
robj *o; robj *o;
long start, end, llen, rangelen; long start, end, llen, rangelen;
if ((getLongFromObjectOrReply(c, c->argv[2], &start, NULL) != REDIS_OK) || if ((getLongFromObjectOrReply(c, c->argv[2], &start, NULL) != C_OK) ||
(getLongFromObjectOrReply(c, c->argv[3], &end, NULL) != REDIS_OK)) return; (getLongFromObjectOrReply(c, c->argv[3], &end, NULL) != C_OK)) return;
if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.emptymultibulk)) == NULL if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.emptymultibulk)) == NULL
|| checkType(c,o,OBJ_LIST)) return; || checkType(c,o,OBJ_LIST)) return;
...@@ -436,8 +436,8 @@ void ltrimCommand(client *c) { ...@@ -436,8 +436,8 @@ void ltrimCommand(client *c) {
robj *o; robj *o;
long start, end, llen, ltrim, rtrim; long start, end, llen, ltrim, rtrim;
if ((getLongFromObjectOrReply(c, c->argv[2], &start, NULL) != REDIS_OK) || if ((getLongFromObjectOrReply(c, c->argv[2], &start, NULL) != C_OK) ||
(getLongFromObjectOrReply(c, c->argv[3], &end, NULL) != REDIS_OK)) return; (getLongFromObjectOrReply(c, c->argv[3], &end, NULL) != C_OK)) return;
if ((o = lookupKeyWriteOrReply(c,c->argv[1],shared.ok)) == NULL || if ((o = lookupKeyWriteOrReply(c,c->argv[1],shared.ok)) == NULL ||
checkType(c,o,OBJ_LIST)) return; checkType(c,o,OBJ_LIST)) return;
...@@ -484,7 +484,7 @@ void lremCommand(client *c) { ...@@ -484,7 +484,7 @@ void lremCommand(client *c) {
long toremove; long toremove;
long removed = 0; long removed = 0;
if ((getLongFromObjectOrReply(c, c->argv[2], &toremove, NULL) != REDIS_OK)) if ((getLongFromObjectOrReply(c, c->argv[2], &toremove, NULL) != C_OK))
return; return;
subject = lookupKeyWriteOrReply(c,c->argv[1],shared.czero); subject = lookupKeyWriteOrReply(c,c->argv[1],shared.czero);
...@@ -716,8 +716,8 @@ void signalListAsReady(redisDb *db, robj *key) { ...@@ -716,8 +716,8 @@ void signalListAsReady(redisDb *db, robj *key) {
* 'value' element was popped fron the head (BLPOP) or tail (BRPOP) so that * 'value' element was popped fron the head (BLPOP) or tail (BRPOP) so that
* we can propagate the command properly. * we can propagate the command properly.
* *
* The function returns REDIS_OK if we are able to serve the client, otherwise * The function returns C_OK if we are able to serve the client, otherwise
* REDIS_ERR is returned to signal the caller that the list POP operation * C_ERR is returned to signal the caller that the list POP operation
* should be undone as the client was not served: This only happens for * should be undone as the client was not served: This only happens for
* BRPOPLPUSH that fails to push the value to the destination key as it is * BRPOPLPUSH that fails to push the value to the destination key as it is
* of the wrong type. */ * of the wrong type. */
...@@ -765,10 +765,10 @@ int serveClientBlockedOnList(client *receiver, robj *key, robj *dstkey, redisDb ...@@ -765,10 +765,10 @@ int serveClientBlockedOnList(client *receiver, robj *key, robj *dstkey, redisDb
} else { } else {
/* BRPOPLPUSH failed because of wrong /* BRPOPLPUSH failed because of wrong
* destination type. */ * destination type. */
return REDIS_ERR; return C_ERR;
} }
} }
return REDIS_OK; return C_OK;
} }
/* This function should be called by Redis every time a single command, /* This function should be called by Redis every time a single command,
...@@ -831,7 +831,7 @@ void handleClientsBlockedOnLists(void) { ...@@ -831,7 +831,7 @@ void handleClientsBlockedOnLists(void) {
if (serveClientBlockedOnList(receiver, if (serveClientBlockedOnList(receiver,
rl->key,dstkey,rl->db,value, rl->key,dstkey,rl->db,value,
where) == REDIS_ERR) where) == C_ERR)
{ {
/* If we failed serving the client we need /* If we failed serving the client we need
* to also undo the POP operation. */ * to also undo the POP operation. */
...@@ -869,7 +869,7 @@ void blockingPopGenericCommand(client *c, int where) { ...@@ -869,7 +869,7 @@ void blockingPopGenericCommand(client *c, int where) {
int j; int j;
if (getTimeoutFromObjectOrReply(c,c->argv[c->argc-1],&timeout,UNIT_SECONDS) if (getTimeoutFromObjectOrReply(c,c->argv[c->argc-1],&timeout,UNIT_SECONDS)
!= REDIS_OK) return; != C_OK) return;
for (j = 1; j < c->argc-1; j++) { for (j = 1; j < c->argc-1; j++) {
o = lookupKeyWrite(c->db,c->argv[j]); o = lookupKeyWrite(c->db,c->argv[j]);
...@@ -931,7 +931,7 @@ void brpoplpushCommand(client *c) { ...@@ -931,7 +931,7 @@ void brpoplpushCommand(client *c) {
mstime_t timeout; mstime_t timeout;
if (getTimeoutFromObjectOrReply(c,c->argv[3],&timeout,UNIT_SECONDS) if (getTimeoutFromObjectOrReply(c,c->argv[3],&timeout,UNIT_SECONDS)
!= REDIS_OK) return; != C_OK) return;
robj *key = lookupKeyWrite(c->db, c->argv[1]); robj *key = lookupKeyWrite(c->db, c->argv[1]);
......
...@@ -40,7 +40,7 @@ void sunionDiffGenericCommand(client *c, robj **setkeys, int setnum, ...@@ -40,7 +40,7 @@ void sunionDiffGenericCommand(client *c, robj **setkeys, int setnum,
* an integer-encodable value, an intset will be returned. Otherwise a regular * an integer-encodable value, an intset will be returned. Otherwise a regular
* hash table. */ * hash table. */
robj *setTypeCreate(robj *value) { robj *setTypeCreate(robj *value) {
if (isObjectRepresentableAsLongLong(value,NULL) == REDIS_OK) if (isObjectRepresentableAsLongLong(value,NULL) == C_OK)
return createIntsetObject(); return createIntsetObject();
return createSetObject(); return createSetObject();
} }
...@@ -58,7 +58,7 @@ int setTypeAdd(robj *subject, robj *value) { ...@@ -58,7 +58,7 @@ int setTypeAdd(robj *subject, robj *value) {
return 1; return 1;
} }
} else if (subject->encoding == OBJ_ENCODING_INTSET) { } else if (subject->encoding == OBJ_ENCODING_INTSET) {
if (isObjectRepresentableAsLongLong(value,&llval) == REDIS_OK) { if (isObjectRepresentableAsLongLong(value,&llval) == C_OK) {
uint8_t success = 0; uint8_t success = 0;
subject->ptr = intsetAdd(subject->ptr,llval,&success); subject->ptr = intsetAdd(subject->ptr,llval,&success);
if (success) { if (success) {
...@@ -93,7 +93,7 @@ int setTypeRemove(robj *setobj, robj *value) { ...@@ -93,7 +93,7 @@ int setTypeRemove(robj *setobj, robj *value) {
return 1; return 1;
} }
} else if (setobj->encoding == OBJ_ENCODING_INTSET) { } else if (setobj->encoding == OBJ_ENCODING_INTSET) {
if (isObjectRepresentableAsLongLong(value,&llval) == REDIS_OK) { if (isObjectRepresentableAsLongLong(value,&llval) == C_OK) {
int success; int success;
setobj->ptr = intsetRemove(setobj->ptr,llval,&success); setobj->ptr = intsetRemove(setobj->ptr,llval,&success);
if (success) return 1; if (success) return 1;
...@@ -109,7 +109,7 @@ int setTypeIsMember(robj *subject, robj *value) { ...@@ -109,7 +109,7 @@ int setTypeIsMember(robj *subject, robj *value) {
if (subject->encoding == OBJ_ENCODING_HT) { if (subject->encoding == OBJ_ENCODING_HT) {
return dictFind((dict*)subject->ptr,value) != NULL; return dictFind((dict*)subject->ptr,value) != NULL;
} else if (subject->encoding == OBJ_ENCODING_INTSET) { } else if (subject->encoding == OBJ_ENCODING_INTSET) {
if (isObjectRepresentableAsLongLong(value,&llval) == REDIS_OK) { if (isObjectRepresentableAsLongLong(value,&llval) == C_OK) {
return intsetFind((intset*)subject->ptr,llval); return intsetFind((intset*)subject->ptr,llval);
} }
} else { } else {
...@@ -413,7 +413,7 @@ void spopWithCountCommand(client *c) { ...@@ -413,7 +413,7 @@ void spopWithCountCommand(client *c) {
robj *set; robj *set;
/* Get the count argument */ /* Get the count argument */
if (getLongFromObjectOrReply(c,c->argv[2],&l,NULL) != REDIS_OK) return; if (getLongFromObjectOrReply(c,c->argv[2],&l,NULL) != C_OK) return;
if (l >= 0) { if (l >= 0) {
count = (unsigned) l; count = (unsigned) l;
} else { } else {
...@@ -626,7 +626,7 @@ void srandmemberWithCountCommand(client *c) { ...@@ -626,7 +626,7 @@ void srandmemberWithCountCommand(client *c) {
dict *d; dict *d;
if (getLongFromObjectOrReply(c,c->argv[2],&l,NULL) != REDIS_OK) return; if (getLongFromObjectOrReply(c,c->argv[2],&l,NULL) != C_OK) return;
if (l >= 0) { if (l >= 0) {
count = (unsigned) l; count = (unsigned) l;
} else { } else {
...@@ -1112,7 +1112,7 @@ void sscanCommand(client *c) { ...@@ -1112,7 +1112,7 @@ void sscanCommand(client *c) {
robj *set; robj *set;
unsigned long cursor; unsigned long cursor;
if (parseScanCursorOrReply(c,c->argv[2],&cursor) == REDIS_ERR) return; if (parseScanCursorOrReply(c,c->argv[2],&cursor) == C_ERR) return;
if ((set = lookupKeyReadOrReply(c,c->argv[1],shared.emptyscan)) == NULL || if ((set = lookupKeyReadOrReply(c,c->argv[1],shared.emptyscan)) == NULL ||
checkType(c,set,OBJ_SET)) return; checkType(c,set,OBJ_SET)) return;
scanGenericCommand(c,set,cursor); scanGenericCommand(c,set,cursor);
......
...@@ -37,9 +37,9 @@ ...@@ -37,9 +37,9 @@
static int checkStringLength(client *c, long long size) { static int checkStringLength(client *c, long long size) {
if (size > 512*1024*1024) { if (size > 512*1024*1024) {
addReplyError(c,"string exceeds maximum allowed size (512MB)"); addReplyError(c,"string exceeds maximum allowed size (512MB)");
return REDIS_ERR; return C_ERR;
} }
return REDIS_OK; return C_OK;
} }
/* The setGenericCommand() function implements the SET operation with different /* The setGenericCommand() function implements the SET operation with different
...@@ -68,7 +68,7 @@ void setGenericCommand(client *c, int flags, robj *key, robj *val, robj *expire, ...@@ -68,7 +68,7 @@ void setGenericCommand(client *c, int flags, robj *key, robj *val, robj *expire,
long long milliseconds = 0; /* initialized to avoid any harmness warning */ long long milliseconds = 0; /* initialized to avoid any harmness warning */
if (expire) { if (expire) {
if (getLongLongFromObjectOrReply(c, expire, &milliseconds, NULL) != REDIS_OK) if (getLongLongFromObjectOrReply(c, expire, &milliseconds, NULL) != C_OK)
return; return;
if (milliseconds <= 0) { if (milliseconds <= 0) {
addReplyErrorFormat(c,"invalid expire time in %s",c->cmd->name); addReplyErrorFormat(c,"invalid expire time in %s",c->cmd->name);
...@@ -158,14 +158,14 @@ int getGenericCommand(client *c) { ...@@ -158,14 +158,14 @@ int getGenericCommand(client *c) {
robj *o; robj *o;
if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.nullbulk)) == NULL) if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.nullbulk)) == NULL)
return REDIS_OK; return C_OK;
if (o->type != OBJ_STRING) { if (o->type != OBJ_STRING) {
addReply(c,shared.wrongtypeerr); addReply(c,shared.wrongtypeerr);
return REDIS_ERR; return C_ERR;
} else { } else {
addReplyBulk(c,o); addReplyBulk(c,o);
return REDIS_OK; return C_OK;
} }
} }
...@@ -174,7 +174,7 @@ void getCommand(client *c) { ...@@ -174,7 +174,7 @@ void getCommand(client *c) {
} }
void getsetCommand(client *c) { void getsetCommand(client *c) {
if (getGenericCommand(c) == REDIS_ERR) return; if (getGenericCommand(c) == C_ERR) return;
c->argv[2] = tryObjectEncoding(c->argv[2]); c->argv[2] = tryObjectEncoding(c->argv[2]);
setKey(c->db,c->argv[1],c->argv[2]); setKey(c->db,c->argv[1],c->argv[2]);
notifyKeyspaceEvent(REDIS_NOTIFY_STRING,"set",c->argv[1],c->db->id); notifyKeyspaceEvent(REDIS_NOTIFY_STRING,"set",c->argv[1],c->db->id);
...@@ -186,7 +186,7 @@ void setrangeCommand(client *c) { ...@@ -186,7 +186,7 @@ void setrangeCommand(client *c) {
long offset; long offset;
sds value = c->argv[3]->ptr; sds value = c->argv[3]->ptr;
if (getLongFromObjectOrReply(c,c->argv[2],&offset,NULL) != REDIS_OK) if (getLongFromObjectOrReply(c,c->argv[2],&offset,NULL) != C_OK)
return; return;
if (offset < 0) { if (offset < 0) {
...@@ -203,7 +203,7 @@ void setrangeCommand(client *c) { ...@@ -203,7 +203,7 @@ void setrangeCommand(client *c) {
} }
/* Return when the resulting string exceeds allowed size */ /* Return when the resulting string exceeds allowed size */
if (checkStringLength(c,offset+sdslen(value)) != REDIS_OK) if (checkStringLength(c,offset+sdslen(value)) != C_OK)
return; return;
o = createObject(OBJ_STRING,sdsnewlen(NULL, offset+sdslen(value))); o = createObject(OBJ_STRING,sdsnewlen(NULL, offset+sdslen(value)));
...@@ -223,7 +223,7 @@ void setrangeCommand(client *c) { ...@@ -223,7 +223,7 @@ void setrangeCommand(client *c) {
} }
/* Return when the resulting string exceeds allowed size */ /* Return when the resulting string exceeds allowed size */
if (checkStringLength(c,offset+sdslen(value)) != REDIS_OK) if (checkStringLength(c,offset+sdslen(value)) != C_OK)
return; return;
/* Create a copy when the object is shared or encoded. */ /* Create a copy when the object is shared or encoded. */
...@@ -247,9 +247,9 @@ void getrangeCommand(client *c) { ...@@ -247,9 +247,9 @@ void getrangeCommand(client *c) {
char *str, llbuf[32]; char *str, llbuf[32];
size_t strlen; size_t strlen;
if (getLongLongFromObjectOrReply(c,c->argv[2],&start,NULL) != REDIS_OK) if (getLongLongFromObjectOrReply(c,c->argv[2],&start,NULL) != C_OK)
return; return;
if (getLongLongFromObjectOrReply(c,c->argv[3],&end,NULL) != REDIS_OK) if (getLongLongFromObjectOrReply(c,c->argv[3],&end,NULL) != C_OK)
return; return;
if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.emptybulk)) == NULL || if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.emptybulk)) == NULL ||
checkType(c,o,OBJ_STRING)) return; checkType(c,o,OBJ_STRING)) return;
...@@ -340,7 +340,7 @@ void incrDecrCommand(client *c, long long incr) { ...@@ -340,7 +340,7 @@ void incrDecrCommand(client *c, long long incr) {
o = lookupKeyWrite(c->db,c->argv[1]); o = lookupKeyWrite(c->db,c->argv[1]);
if (o != NULL && checkType(c,o,OBJ_STRING)) return; if (o != NULL && checkType(c,o,OBJ_STRING)) return;
if (getLongLongFromObjectOrReply(c,o,&value,NULL) != REDIS_OK) return; if (getLongLongFromObjectOrReply(c,o,&value,NULL) != C_OK) return;
oldvalue = value; oldvalue = value;
if ((incr < 0 && oldvalue < 0 && incr < (LLONG_MIN-oldvalue)) || if ((incr < 0 && oldvalue < 0 && incr < (LLONG_MIN-oldvalue)) ||
...@@ -383,14 +383,14 @@ void decrCommand(client *c) { ...@@ -383,14 +383,14 @@ void decrCommand(client *c) {
void incrbyCommand(client *c) { void incrbyCommand(client *c) {
long long incr; long long incr;
if (getLongLongFromObjectOrReply(c, c->argv[2], &incr, NULL) != REDIS_OK) return; if (getLongLongFromObjectOrReply(c, c->argv[2], &incr, NULL) != C_OK) return;
incrDecrCommand(c,incr); incrDecrCommand(c,incr);
} }
void decrbyCommand(client *c) { void decrbyCommand(client *c) {
long long incr; long long incr;
if (getLongLongFromObjectOrReply(c, c->argv[2], &incr, NULL) != REDIS_OK) return; if (getLongLongFromObjectOrReply(c, c->argv[2], &incr, NULL) != C_OK) return;
incrDecrCommand(c,-incr); incrDecrCommand(c,-incr);
} }
...@@ -400,8 +400,8 @@ void incrbyfloatCommand(client *c) { ...@@ -400,8 +400,8 @@ void incrbyfloatCommand(client *c) {
o = lookupKeyWrite(c->db,c->argv[1]); o = lookupKeyWrite(c->db,c->argv[1]);
if (o != NULL && checkType(c,o,OBJ_STRING)) return; if (o != NULL && checkType(c,o,OBJ_STRING)) return;
if (getLongDoubleFromObjectOrReply(c,o,&value,NULL) != REDIS_OK || if (getLongDoubleFromObjectOrReply(c,o,&value,NULL) != C_OK ||
getLongDoubleFromObjectOrReply(c,c->argv[2],&incr,NULL) != REDIS_OK) getLongDoubleFromObjectOrReply(c,c->argv[2],&incr,NULL) != C_OK)
return; return;
value += incr; value += incr;
...@@ -447,7 +447,7 @@ void appendCommand(client *c) { ...@@ -447,7 +447,7 @@ void appendCommand(client *c) {
/* "append" is an argument, so always an sds */ /* "append" is an argument, so always an sds */
append = c->argv[2]; append = c->argv[2];
totlen = stringObjectLen(o)+sdslen(append->ptr); totlen = stringObjectLen(o)+sdslen(append->ptr);
if (checkStringLength(c,totlen) != REDIS_OK) if (checkStringLength(c,totlen) != C_OK)
return; return;
/* Append the value */ /* Append the value */
......
...@@ -440,11 +440,11 @@ static int zslParseRange(robj *min, robj *max, zrangespec *spec) { ...@@ -440,11 +440,11 @@ static int zslParseRange(robj *min, robj *max, zrangespec *spec) {
} else { } else {
if (((char*)min->ptr)[0] == '(') { if (((char*)min->ptr)[0] == '(') {
spec->min = strtod((char*)min->ptr+1,&eptr); spec->min = strtod((char*)min->ptr+1,&eptr);
if (eptr[0] != '\0' || isnan(spec->min)) return REDIS_ERR; if (eptr[0] != '\0' || isnan(spec->min)) return C_ERR;
spec->minex = 1; spec->minex = 1;
} else { } else {
spec->min = strtod((char*)min->ptr,&eptr); spec->min = strtod((char*)min->ptr,&eptr);
if (eptr[0] != '\0' || isnan(spec->min)) return REDIS_ERR; if (eptr[0] != '\0' || isnan(spec->min)) return C_ERR;
} }
} }
if (max->encoding == OBJ_ENCODING_INT) { if (max->encoding == OBJ_ENCODING_INT) {
...@@ -452,15 +452,15 @@ static int zslParseRange(robj *min, robj *max, zrangespec *spec) { ...@@ -452,15 +452,15 @@ static int zslParseRange(robj *min, robj *max, zrangespec *spec) {
} else { } else {
if (((char*)max->ptr)[0] == '(') { if (((char*)max->ptr)[0] == '(') {
spec->max = strtod((char*)max->ptr+1,&eptr); spec->max = strtod((char*)max->ptr+1,&eptr);
if (eptr[0] != '\0' || isnan(spec->max)) return REDIS_ERR; if (eptr[0] != '\0' || isnan(spec->max)) return C_ERR;
spec->maxex = 1; spec->maxex = 1;
} else { } else {
spec->max = strtod((char*)max->ptr,&eptr); spec->max = strtod((char*)max->ptr,&eptr);
if (eptr[0] != '\0' || isnan(spec->max)) return REDIS_ERR; if (eptr[0] != '\0' || isnan(spec->max)) return C_ERR;
} }
} }
return REDIS_OK; return C_OK;
} }
/* ------------------------ Lexicographic ranges ---------------------------- */ /* ------------------------ Lexicographic ranges ---------------------------- */
...@@ -473,64 +473,64 @@ static int zslParseRange(robj *min, robj *max, zrangespec *spec) { ...@@ -473,64 +473,64 @@ static int zslParseRange(robj *min, robj *max, zrangespec *spec) {
* *
* If the string is valid the *dest pointer is set to the redis object * If the string is valid the *dest pointer is set to the redis object
* that will be used for the comparision, and ex will be set to 0 or 1 * that will be used for the comparision, and ex will be set to 0 or 1
* respectively if the item is exclusive or inclusive. REDIS_OK will be * respectively if the item is exclusive or inclusive. C_OK will be
* returned. * returned.
* *
* If the string is not a valid range REDIS_ERR is returned, and the value * If the string is not a valid range C_ERR is returned, and the value
* of *dest and *ex is undefined. */ * of *dest and *ex is undefined. */
int zslParseLexRangeItem(robj *item, robj **dest, int *ex) { int zslParseLexRangeItem(robj *item, robj **dest, int *ex) {
char *c = item->ptr; char *c = item->ptr;
switch(c[0]) { switch(c[0]) {
case '+': case '+':
if (c[1] != '\0') return REDIS_ERR; if (c[1] != '\0') return C_ERR;
*ex = 0; *ex = 0;
*dest = shared.maxstring; *dest = shared.maxstring;
incrRefCount(shared.maxstring); incrRefCount(shared.maxstring);
return REDIS_OK; return C_OK;
case '-': case '-':
if (c[1] != '\0') return REDIS_ERR; if (c[1] != '\0') return C_ERR;
*ex = 0; *ex = 0;
*dest = shared.minstring; *dest = shared.minstring;
incrRefCount(shared.minstring); incrRefCount(shared.minstring);
return REDIS_OK; return C_OK;
case '(': case '(':
*ex = 1; *ex = 1;
*dest = createStringObject(c+1,sdslen(c)-1); *dest = createStringObject(c+1,sdslen(c)-1);
return REDIS_OK; return C_OK;
case '[': case '[':
*ex = 0; *ex = 0;
*dest = createStringObject(c+1,sdslen(c)-1); *dest = createStringObject(c+1,sdslen(c)-1);
return REDIS_OK; return C_OK;
default: default:
return REDIS_ERR; return C_ERR;
} }
} }
/* Populate the rangespec according to the objects min and max. /* Populate the rangespec according to the objects min and max.
* *
* Return REDIS_OK on success. On error REDIS_ERR is returned. * Return C_OK on success. On error C_ERR is returned.
* When OK is returned the structure must be freed with zslFreeLexRange(), * When OK is returned the structure must be freed with zslFreeLexRange(),
* otherwise no release is needed. */ * otherwise no release is needed. */
static int zslParseLexRange(robj *min, robj *max, zlexrangespec *spec) { static int zslParseLexRange(robj *min, robj *max, zlexrangespec *spec) {
/* The range can't be valid if objects are integer encoded. /* The range can't be valid if objects are integer encoded.
* Every item must start with ( or [. */ * Every item must start with ( or [. */
if (min->encoding == OBJ_ENCODING_INT || if (min->encoding == OBJ_ENCODING_INT ||
max->encoding == OBJ_ENCODING_INT) return REDIS_ERR; max->encoding == OBJ_ENCODING_INT) return C_ERR;
spec->min = spec->max = NULL; spec->min = spec->max = NULL;
if (zslParseLexRangeItem(min, &spec->min, &spec->minex) == REDIS_ERR || if (zslParseLexRangeItem(min, &spec->min, &spec->minex) == C_ERR ||
zslParseLexRangeItem(max, &spec->max, &spec->maxex) == REDIS_ERR) { zslParseLexRangeItem(max, &spec->max, &spec->maxex) == C_ERR) {
if (spec->min) decrRefCount(spec->min); if (spec->min) decrRefCount(spec->min);
if (spec->max) decrRefCount(spec->max); if (spec->max) decrRefCount(spec->max);
return REDIS_ERR; return C_ERR;
} else { } else {
return REDIS_OK; return C_OK;
} }
} }
/* Free a lex range structure, must be called only after zelParseLexRange() /* Free a lex range structure, must be called only after zelParseLexRange()
* populated the structure with success (REDIS_OK returned). */ * populated the structure with success (C_OK returned). */
void zslFreeLexRange(zlexrangespec *spec) { void zslFreeLexRange(zlexrangespec *spec) {
decrRefCount(spec->min); decrRefCount(spec->min);
decrRefCount(spec->max); decrRefCount(spec->max);
...@@ -1167,23 +1167,23 @@ void zsetConvert(robj *zobj, int encoding) { ...@@ -1167,23 +1167,23 @@ void zsetConvert(robj *zobj, int encoding) {
} }
/* Return (by reference) the score of the specified member of the sorted set /* Return (by reference) the score of the specified member of the sorted set
* storing it into *score. If the element does not exist REDIS_ERR is returned * storing it into *score. If the element does not exist C_ERR is returned
* otherwise REDIS_OK is returned and *score is correctly populated. * otherwise C_OK is returned and *score is correctly populated.
* If 'zobj' or 'member' is NULL, REDIS_ERR is returned. */ * If 'zobj' or 'member' is NULL, C_ERR is returned. */
int zsetScore(robj *zobj, robj *member, double *score) { int zsetScore(robj *zobj, robj *member, double *score) {
if (!zobj || !member) return REDIS_ERR; if (!zobj || !member) return C_ERR;
if (zobj->encoding == OBJ_ENCODING_ZIPLIST) { if (zobj->encoding == OBJ_ENCODING_ZIPLIST) {
if (zzlFind(zobj->ptr, member, score) == NULL) return REDIS_ERR; if (zzlFind(zobj->ptr, member, score) == NULL) return C_ERR;
} else if (zobj->encoding == OBJ_ENCODING_SKIPLIST) { } else if (zobj->encoding == OBJ_ENCODING_SKIPLIST) {
zset *zs = zobj->ptr; zset *zs = zobj->ptr;
dictEntry *de = dictFind(zs->dict, member); dictEntry *de = dictFind(zs->dict, member);
if (de == NULL) return REDIS_ERR; if (de == NULL) return C_ERR;
*score = *(double*)dictGetVal(de); *score = *(double*)dictGetVal(de);
} else { } else {
redisPanic("Unknown sorted set encoding"); redisPanic("Unknown sorted set encoding");
} }
return REDIS_OK; return C_OK;
} }
/*----------------------------------------------------------------------------- /*-----------------------------------------------------------------------------
...@@ -1260,7 +1260,7 @@ void zaddGenericCommand(client *c, int flags) { ...@@ -1260,7 +1260,7 @@ void zaddGenericCommand(client *c, int flags) {
scores = zmalloc(sizeof(double)*elements); scores = zmalloc(sizeof(double)*elements);
for (j = 0; j < elements; j++) { for (j = 0; j < elements; j++) {
if (getDoubleFromObjectOrReply(c,c->argv[scoreidx+j*2],&scores[j],NULL) if (getDoubleFromObjectOrReply(c,c->argv[scoreidx+j*2],&scores[j],NULL)
!= REDIS_OK) goto cleanup; != C_OK) goto cleanup;
} }
/* Lookup the key and create the sorted set if does not exist. */ /* Lookup the key and create the sorted set if does not exist. */
...@@ -1471,16 +1471,16 @@ void zremrangeGenericCommand(client *c, int rangetype) { ...@@ -1471,16 +1471,16 @@ void zremrangeGenericCommand(client *c, int rangetype) {
/* Step 1: Parse the range. */ /* Step 1: Parse the range. */
if (rangetype == ZRANGE_RANK) { if (rangetype == ZRANGE_RANK) {
if ((getLongFromObjectOrReply(c,c->argv[2],&start,NULL) != REDIS_OK) || if ((getLongFromObjectOrReply(c,c->argv[2],&start,NULL) != C_OK) ||
(getLongFromObjectOrReply(c,c->argv[3],&end,NULL) != REDIS_OK)) (getLongFromObjectOrReply(c,c->argv[3],&end,NULL) != C_OK))
return; return;
} else if (rangetype == ZRANGE_SCORE) { } else if (rangetype == ZRANGE_SCORE) {
if (zslParseRange(c->argv[2],c->argv[3],&range) != REDIS_OK) { if (zslParseRange(c->argv[2],c->argv[3],&range) != C_OK) {
addReplyError(c,"min or max is not a float"); addReplyError(c,"min or max is not a float");
return; return;
} }
} else if (rangetype == ZRANGE_LEX) { } else if (rangetype == ZRANGE_LEX) {
if (zslParseLexRange(c->argv[2],c->argv[3],&lexrange) != REDIS_OK) { if (zslParseLexRange(c->argv[2],c->argv[3],&lexrange) != C_OK) {
addReplyError(c,"min or max not valid string range item"); addReplyError(c,"min or max not valid string range item");
return; return;
} }
...@@ -1936,7 +1936,7 @@ void zunionInterGenericCommand(client *c, robj *dstkey, int op) { ...@@ -1936,7 +1936,7 @@ void zunionInterGenericCommand(client *c, robj *dstkey, int op) {
int touched = 0; int touched = 0;
/* expect setnum input keys to be given */ /* expect setnum input keys to be given */
if ((getLongFromObjectOrReply(c, c->argv[2], &setnum, NULL) != REDIS_OK)) if ((getLongFromObjectOrReply(c, c->argv[2], &setnum, NULL) != C_OK))
return; return;
if (setnum < 1) { if (setnum < 1) {
...@@ -1982,7 +1982,7 @@ void zunionInterGenericCommand(client *c, robj *dstkey, int op) { ...@@ -1982,7 +1982,7 @@ void zunionInterGenericCommand(client *c, robj *dstkey, int op) {
j++; remaining--; j++; remaining--;
for (i = 0; i < setnum; i++, j++, remaining--) { for (i = 0; i < setnum; i++, j++, remaining--) {
if (getDoubleFromObjectOrReply(c,c->argv[j],&src[i].weight, if (getDoubleFromObjectOrReply(c,c->argv[j],&src[i].weight,
"weight value is not a float") != REDIS_OK) "weight value is not a float") != C_OK)
{ {
zfree(src); zfree(src);
return; return;
...@@ -2180,8 +2180,8 @@ void zrangeGenericCommand(client *c, int reverse) { ...@@ -2180,8 +2180,8 @@ void zrangeGenericCommand(client *c, int reverse) {
int llen; int llen;
int rangelen; int rangelen;
if ((getLongFromObjectOrReply(c, c->argv[2], &start, NULL) != REDIS_OK) || if ((getLongFromObjectOrReply(c, c->argv[2], &start, NULL) != C_OK) ||
(getLongFromObjectOrReply(c, c->argv[3], &end, NULL) != REDIS_OK)) return; (getLongFromObjectOrReply(c, c->argv[3], &end, NULL) != C_OK)) return;
if (c->argc == 5 && !strcasecmp(c->argv[4]->ptr,"withscores")) { if (c->argc == 5 && !strcasecmp(c->argv[4]->ptr,"withscores")) {
withscores = 1; withscores = 1;
...@@ -2301,7 +2301,7 @@ void genericZrangebyscoreCommand(client *c, int reverse) { ...@@ -2301,7 +2301,7 @@ void genericZrangebyscoreCommand(client *c, int reverse) {
minidx = 2; maxidx = 3; minidx = 2; maxidx = 3;
} }
if (zslParseRange(c->argv[minidx],c->argv[maxidx],&range) != REDIS_OK) { if (zslParseRange(c->argv[minidx],c->argv[maxidx],&range) != C_OK) {
addReplyError(c,"min or max is not a float"); addReplyError(c,"min or max is not a float");
return; return;
} }
...@@ -2317,8 +2317,8 @@ void genericZrangebyscoreCommand(client *c, int reverse) { ...@@ -2317,8 +2317,8 @@ void genericZrangebyscoreCommand(client *c, int reverse) {
pos++; remaining--; pos++; remaining--;
withscores = 1; withscores = 1;
} else if (remaining >= 3 && !strcasecmp(c->argv[pos]->ptr,"limit")) { } else if (remaining >= 3 && !strcasecmp(c->argv[pos]->ptr,"limit")) {
if ((getLongFromObjectOrReply(c, c->argv[pos+1], &offset, NULL) != REDIS_OK) || if ((getLongFromObjectOrReply(c, c->argv[pos+1], &offset, NULL) != C_OK) ||
(getLongFromObjectOrReply(c, c->argv[pos+2], &limit, NULL) != REDIS_OK)) return; (getLongFromObjectOrReply(c, c->argv[pos+2], &limit, NULL) != C_OK)) return;
pos += 3; remaining -= 3; pos += 3; remaining -= 3;
} else { } else {
addReply(c,shared.syntaxerr); addReply(c,shared.syntaxerr);
...@@ -2483,7 +2483,7 @@ void zcountCommand(client *c) { ...@@ -2483,7 +2483,7 @@ void zcountCommand(client *c) {
int count = 0; int count = 0;
/* Parse the range arguments */ /* Parse the range arguments */
if (zslParseRange(c->argv[2],c->argv[3],&range) != REDIS_OK) { if (zslParseRange(c->argv[2],c->argv[3],&range) != C_OK) {
addReplyError(c,"min or max is not a float"); addReplyError(c,"min or max is not a float");
return; return;
} }
...@@ -2560,7 +2560,7 @@ void zlexcountCommand(client *c) { ...@@ -2560,7 +2560,7 @@ void zlexcountCommand(client *c) {
int count = 0; int count = 0;
/* Parse the range arguments */ /* Parse the range arguments */
if (zslParseLexRange(c->argv[2],c->argv[3],&range) != REDIS_OK) { if (zslParseLexRange(c->argv[2],c->argv[3],&range) != C_OK) {
addReplyError(c,"min or max not valid string range item"); addReplyError(c,"min or max not valid string range item");
return; return;
} }
...@@ -2651,7 +2651,7 @@ void genericZrangebylexCommand(client *c, int reverse) { ...@@ -2651,7 +2651,7 @@ void genericZrangebylexCommand(client *c, int reverse) {
minidx = 2; maxidx = 3; minidx = 2; maxidx = 3;
} }
if (zslParseLexRange(c->argv[minidx],c->argv[maxidx],&range) != REDIS_OK) { if (zslParseLexRange(c->argv[minidx],c->argv[maxidx],&range) != C_OK) {
addReplyError(c,"min or max not valid string range item"); addReplyError(c,"min or max not valid string range item");
return; return;
} }
...@@ -2664,8 +2664,8 @@ void genericZrangebylexCommand(client *c, int reverse) { ...@@ -2664,8 +2664,8 @@ void genericZrangebylexCommand(client *c, int reverse) {
while (remaining) { while (remaining) {
if (remaining >= 3 && !strcasecmp(c->argv[pos]->ptr,"limit")) { if (remaining >= 3 && !strcasecmp(c->argv[pos]->ptr,"limit")) {
if ((getLongFromObjectOrReply(c, c->argv[pos+1], &offset, NULL) != REDIS_OK) || if ((getLongFromObjectOrReply(c, c->argv[pos+1], &offset, NULL) != C_OK) ||
(getLongFromObjectOrReply(c, c->argv[pos+2], &limit, NULL) != REDIS_OK)) return; (getLongFromObjectOrReply(c, c->argv[pos+2], &limit, NULL) != C_OK)) return;
pos += 3; remaining -= 3; pos += 3; remaining -= 3;
} else { } else {
zslFreeLexRange(&range); zslFreeLexRange(&range);
...@@ -2835,7 +2835,7 @@ void zscoreCommand(client *c) { ...@@ -2835,7 +2835,7 @@ void zscoreCommand(client *c) {
if ((zobj = lookupKeyReadOrReply(c,key,shared.nullbulk)) == NULL || if ((zobj = lookupKeyReadOrReply(c,key,shared.nullbulk)) == NULL ||
checkType(c,zobj,OBJ_ZSET)) return; checkType(c,zobj,OBJ_ZSET)) return;
if (zsetScore(zobj,c->argv[2],&score) == REDIS_ERR) { if (zsetScore(zobj,c->argv[2],&score) == C_ERR) {
addReply(c,shared.nullbulk); addReply(c,shared.nullbulk);
} else { } else {
addReplyDouble(c,score); addReplyDouble(c,score);
...@@ -2916,7 +2916,7 @@ void zscanCommand(client *c) { ...@@ -2916,7 +2916,7 @@ void zscanCommand(client *c) {
robj *o; robj *o;
unsigned long cursor; unsigned long cursor;
if (parseScanCursorOrReply(c,c->argv[2],&cursor) == REDIS_ERR) return; if (parseScanCursorOrReply(c,c->argv[2],&cursor) == C_ERR) return;
if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.emptyscan)) == NULL || if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.emptyscan)) == NULL ||
checkType(c,o,OBJ_ZSET)) return; checkType(c,o,OBJ_ZSET)) return;
scanGenericCommand(c,o,cursor); scanGenericCommand(c,o,cursor);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment