Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
ad30aa60
Commit
ad30aa60
authored
May 11, 2010
by
antirez
Browse files
load objects encoded from disk directly without useless conversion
parent
bd59ecfb
Changes
1
Hide whitespace changes
Inline
Side-by-side
redis.c
View file @
ad30aa60
...
...
@@ -3797,7 +3797,11 @@ static uint32_t rdbLoadLen(FILE *fp, int *isencoded) {
}
}
static
robj
*
rdbLoadIntegerObject
(
FILE
*
fp
,
int
enctype
)
{
/* Load an integer-encoded object from file 'fp', with the specified
* encoding type 'enctype'. If encode is true the function may return
* an integer-encoded object as reply, otherwise the returned object
* will always be encoded as a raw string. */
static robj *rdbLoadIntegerObject(FILE *fp, int enctype, int encode) {
unsigned char enc[4];
long long val;
...
...
@@ -3818,7 +3822,10 @@ static robj *rdbLoadIntegerObject(FILE *fp, int enctype) {
val = 0; /* anti-warning */
redisPanic("Unknown RDB integer encoding type");
}
return
createObject
(
REDIS_STRING
,
sdsfromlonglong
(
val
));
if (encode)
return createStringObjectFromLongLong(val);
else
return createObject(REDIS_STRING,sdsfromlonglong(val));
}
static robj *rdbLoadLzfStringObject(FILE*fp) {
...
...
@@ -3840,7 +3847,7 @@ err:
return NULL;
}
static
robj
*
rdbLoadStringObject
(
FILE
*
fp
)
{
static robj *rdb
Generic
LoadStringObject(FILE*fp
, int encode
) {
int isencoded;
uint32_t len;
sds val;
...
...
@@ -3851,7 +3858,7 @@ static robj *rdbLoadStringObject(FILE*fp) {
case REDIS_RDB_ENC_INT8:
case REDIS_RDB_ENC_INT16:
case REDIS_RDB_ENC_INT32:
return
rdbLoadIntegerObject
(
fp
,
len
);
return rdbLoadIntegerObject(fp,len
,encode
);
case REDIS_RDB_ENC_LZF:
return rdbLoadLzfStringObject(fp);
default:
...
...
@@ -3868,6 +3875,14 @@ static robj *rdbLoadStringObject(FILE*fp) {
return createObject(REDIS_STRING,val);
}
static robj *rdbLoadStringObject(FILE *fp) {
return rdbGenericLoadStringObject(fp,0);
}
static robj *rdbLoadEncodedStringObject(FILE *fp) {
return rdbGenericLoadStringObject(fp,1);
}
/* For information about double serialization check rdbSaveDoubleValue() */
static int rdbLoadDoubleValue(FILE *fp, double *val) {
char buf[128];
...
...
@@ -3894,7 +3909,7 @@ static robj *rdbLoadObject(int type, FILE *fp) {
redisLog(REDIS_DEBUG,"LOADING OBJECT %d (at %d)\n",type,ftell(fp));
if (type == REDIS_STRING) {
/* Read string value */
if
((
o
=
rdbLoadStringObject
(
fp
))
==
NULL
)
return
NULL
;
if ((o = rdbLoad
Encoded
StringObject(fp)) == NULL) return NULL;
o = tryObjectEncoding(o);
} else if (type == REDIS_LIST || type == REDIS_SET) {
/* Read list/set value */
...
...
@@ -3910,7 +3925,7 @@ static robj *rdbLoadObject(int type, FILE *fp) {
while(listlen--) {
robj *ele;
if
((
ele
=
rdbLoadStringObject
(
fp
))
==
NULL
)
return
NULL
;
if ((ele = rdbLoad
Encoded
StringObject(fp)) == NULL) return NULL;
ele = tryObjectEncoding(ele);
if (type == REDIS_LIST) {
listAddNodeTail((list*)o->ptr,ele);
...
...
@@ -3931,7 +3946,7 @@ static robj *rdbLoadObject(int type, FILE *fp) {
robj *ele;
double *score = zmalloc(sizeof(double));
if
((
ele
=
rdbLoadStringObject
(
fp
))
==
NULL
)
return
NULL
;
if ((ele = rdbLoad
Encoded
StringObject(fp)) == NULL) return NULL;
ele = tryObjectEncoding(ele);
if (rdbLoadDoubleValue(fp,score) == -1) return NULL;
dictAdd(zs->dict,ele,score);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment