X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/7d8c555e92954b02d40c15702476fd48e55c4f94..da386cdf337a79b6734b58d3c5e426741e49c043:/src/object.c diff --git a/src/object.c b/src/object.c index 4bf1df01..22f53837 100644 --- a/src/object.c +++ b/src/object.c @@ -144,7 +144,7 @@ void freeSetObject(robj *o) { void freeZsetObject(robj *o) { zset *zs; switch (o->encoding) { - case REDIS_ENCODING_RAW: + case REDIS_ENCODING_SKIPLIST: zs = o->ptr; dictRelease(zs->dict); zslFree(zs->zsl); @@ -202,6 +202,16 @@ int checkType(redisClient *c, robj *o, int type) { return 0; } +int isObjectRepresentableAsLongLong(robj *o, long long *llval) { + redisAssert(o->type == REDIS_STRING); + if (o->encoding == REDIS_ENCODING_INT) { + if (llval) *llval = (long) o->ptr; + return REDIS_OK; + } else { + return string2ll(o->ptr,sdslen(o->ptr),llval) ? REDIS_OK : REDIS_ERR; + } +} + /* Try to encode a string object in order to save space */ robj *tryObjectEncoding(robj *o) { long value; @@ -219,7 +229,7 @@ robj *tryObjectEncoding(robj *o) { redisAssert(o->type == REDIS_STRING); /* Check if we can represent this string as a long integer */ - if (isStringRepresentableAsLong(s,&value) == REDIS_ERR) return o; + if (!string2l(s,sdslen(s),&value)) return o; /* Ok, this object can be encoded... *