Created
March 29, 2010 13:08
-
-
Save alexmchale/347814 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static int getDoubleFromObject(redisClient *c, robj *o, double *value) { | |
double parsedValue; | |
char *eptr = NULL; | |
if (o && o->type != REDIS_STRING) { | |
addReplySds(c,sdsnew("-ERR value is not a double\r\n")); | |
return REDIS_ERR; | |
} | |
if (o == NULL) | |
parsedValue = 0; | |
else if (o->encoding == REDIS_ENCODING_RAW) | |
parsedValue = strtod(o->ptr, &eptr); | |
else if (o->encoding == REDIS_ENCODING_INT) | |
parsedValue = (long)o->ptr; | |
else | |
redisAssert(1 != 1); | |
if (eptr != NULL && *eptr != '\0') { | |
addReplySds(c,sdsnew("-ERR value is not a double\r\n")); | |
return REDIS_ERR; | |
} | |
*value = parsedValue; | |
return REDIS_OK; | |
} | |
static int getLongFromObject(redisClient *c, robj *o, long *value) { | |
long parsedValue; | |
char *eptr = NULL; | |
if (o && o->type != REDIS_STRING) { | |
addReplySds(c,sdsnew("-ERR value is not an integer\r\n")); | |
return REDIS_ERR; | |
} | |
if (o == NULL) | |
parsedValue = 0; | |
else if (o->encoding == REDIS_ENCODING_RAW) | |
parsedValue = strtol(o->ptr, &eptr, 10); | |
else if (o->encoding == REDIS_ENCODING_INT) | |
parsedValue = (long)o->ptr; | |
else | |
redisAssert(1 != 1); | |
if (eptr != NULL && *eptr != '\0') { | |
addReplySds(c,sdsnew("-ERR value is not an integer\r\n")); | |
return REDIS_ERR; | |
} | |
*value = parsedValue; | |
return REDIS_OK; | |
} | |
static int getLongLongFromObject(redisClient *c, robj *o, long long *value) { | |
long long parsedValue; | |
char *eptr = NULL; | |
if (o && o->type != REDIS_STRING) { | |
addReplySds(c,sdsnew("-ERR value is not an integer\r\n")); | |
return REDIS_ERR; | |
} | |
if (o == NULL) | |
parsedValue = 0; | |
else if (o->encoding == REDIS_ENCODING_RAW) | |
parsedValue = strtoll(o->ptr, &eptr, 10); | |
else if (o->encoding == REDIS_ENCODING_INT) | |
parsedValue = (long)o->ptr; | |
else | |
redisAssert(1 != 1); | |
if (eptr != NULL && *eptr != '\0') { | |
addReplySds(c,sdsnew("-ERR value is not an integer\r\n")); | |
return REDIS_ERR; | |
} | |
*value = parsedValue; | |
return REDIS_OK; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment