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
88e85998
Commit
88e85998
authored
Apr 02, 2009
by
antirez
Browse files
compression/decompression of large values on disk now working
parent
40c32c3e
Changes
1
Hide whitespace changes
Inline
Side-by-side
redis.c
View file @
88e85998
...
@@ -1657,7 +1657,7 @@ static int rdbSaveLzfStringObject(FILE *fp, robj *obj) {
...
@@ -1657,7 +1657,7 @@ static int rdbSaveLzfStringObject(FILE *fp, robj *obj) {
if
((
out
=
zmalloc
(
outlen
))
==
NULL
)
return
0
;
if
((
out
=
zmalloc
(
outlen
))
==
NULL
)
return
0
;
comprlen
=
lzf_compress
(
obj
->
ptr
,
sdslen
(
obj
->
ptr
),
out
,
outlen
);
comprlen
=
lzf_compress
(
obj
->
ptr
,
sdslen
(
obj
->
ptr
),
out
,
outlen
);
if
(
comprlen
==
0
)
{
if
(
comprlen
==
0
)
{
free
(
out
);
z
free
(
out
);
return
0
;
return
0
;
}
}
/* Data compressed! Let's save it on disk */
/* Data compressed! Let's save it on disk */
...
@@ -1666,11 +1666,11 @@ static int rdbSaveLzfStringObject(FILE *fp, robj *obj) {
...
@@ -1666,11 +1666,11 @@ static int rdbSaveLzfStringObject(FILE *fp, robj *obj) {
if
(
rdbSaveLen
(
fp
,
comprlen
)
==
-
1
)
goto
writeerr
;
if
(
rdbSaveLen
(
fp
,
comprlen
)
==
-
1
)
goto
writeerr
;
if
(
rdbSaveLen
(
fp
,
sdslen
(
obj
->
ptr
))
==
-
1
)
goto
writeerr
;
if
(
rdbSaveLen
(
fp
,
sdslen
(
obj
->
ptr
))
==
-
1
)
goto
writeerr
;
if
(
fwrite
(
out
,
comprlen
,
1
,
fp
)
==
0
)
goto
writeerr
;
if
(
fwrite
(
out
,
comprlen
,
1
,
fp
)
==
0
)
goto
writeerr
;
free
(
out
);
z
free
(
out
);
return
comprlen
;
return
comprlen
;
writeerr:
writeerr:
free
(
out
);
z
free
(
out
);
return
-
1
;
return
-
1
;
}
}
...
@@ -1690,8 +1690,8 @@ static int rdbSaveStringObject(FILE *fp, robj *obj) {
...
@@ -1690,8 +1690,8 @@ static int rdbSaveStringObject(FILE *fp, robj *obj) {
}
}
/* Try LZF compression - under 20 bytes it's unable to compress even
/* Try LZF compression - under 20 bytes it's unable to compress even
* aaaaaaaaaaaaaaaaaa so
to try is just useful to make the CPU ho
t */
* aaaaaaaaaaaaaaaaaa so
skip i
t */
if
(
0
&&
len
>
20
)
{
if
(
len
>
20
)
{
int
retval
;
int
retval
;
retval
=
rdbSaveLzfStringObject
(
fp
,
obj
);
retval
=
rdbSaveLzfStringObject
(
fp
,
obj
);
...
@@ -1892,6 +1892,24 @@ static robj *rdbLoadIntegerObject(FILE *fp, int enctype) {
...
@@ -1892,6 +1892,24 @@ static robj *rdbLoadIntegerObject(FILE *fp, int enctype) {
return
createObject
(
REDIS_STRING
,
sdscatprintf
(
sdsempty
(),
"%lld"
,
val
));
return
createObject
(
REDIS_STRING
,
sdscatprintf
(
sdsempty
(),
"%lld"
,
val
));
}
}
static
robj
*
rdbLoadLzfStringObject
(
FILE
*
fp
,
int
rdbver
)
{
unsigned
int
len
,
clen
;
unsigned
char
*
c
=
NULL
;
sds
val
=
NULL
;
if
((
clen
=
rdbLoadLen
(
fp
,
rdbver
,
NULL
))
==
REDIS_RDB_LENERR
)
return
NULL
;
if
((
len
=
rdbLoadLen
(
fp
,
rdbver
,
NULL
))
==
REDIS_RDB_LENERR
)
return
NULL
;
if
((
c
=
zmalloc
(
clen
))
==
NULL
)
goto
err
;
if
((
val
=
sdsnewlen
(
NULL
,
len
))
==
NULL
)
goto
err
;
if
(
fread
(
c
,
clen
,
1
,
fp
)
==
0
)
goto
err
;
if
(
lzf_decompress
(
c
,
clen
,
val
,
len
)
==
0
)
goto
err
;
return
createObject
(
REDIS_STRING
,
val
);
err:
zfree
(
c
);
sdsfree
(
val
);
return
NULL
;
}
static
robj
*
rdbLoadStringObject
(
FILE
*
fp
,
int
rdbver
)
{
static
robj
*
rdbLoadStringObject
(
FILE
*
fp
,
int
rdbver
)
{
int
isencoded
;
int
isencoded
;
uint32_t
len
;
uint32_t
len
;
...
@@ -1904,6 +1922,8 @@ static robj *rdbLoadStringObject(FILE*fp, int rdbver) {
...
@@ -1904,6 +1922,8 @@ static robj *rdbLoadStringObject(FILE*fp, int rdbver) {
case
REDIS_RDB_ENC_INT16
:
case
REDIS_RDB_ENC_INT16
:
case
REDIS_RDB_ENC_INT32
:
case
REDIS_RDB_ENC_INT32
:
return
tryObjectSharing
(
rdbLoadIntegerObject
(
fp
,
len
));
return
tryObjectSharing
(
rdbLoadIntegerObject
(
fp
,
len
));
case
REDIS_RDB_ENC_LZF
:
return
tryObjectSharing
(
rdbLoadLzfStringObject
(
fp
,
rdbver
));
default:
default:
assert
(
0
!=
0
);
assert
(
0
!=
0
);
}
}
...
...
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