Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xindoo
redis
提交
a4961a9a
R
redis
项目概览
xindoo
/
redis
通知
2
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redis
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
a4961a9a
编写于
4月 04, 2014
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
No hard limits to LZF compression max size.
上级
eed8495b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
23 addition
and
8 deletion
+23
-8
src/object.c
src/object.c
+20
-8
src/redis.c
src/redis.c
+1
-0
src/redis.h
src/redis.h
+2
-0
未找到文件。
src/object.c
浏览文件 @
a4961a9a
...
...
@@ -338,8 +338,7 @@ int isObjectRepresentableAsLongLong(robj *o, long long *llval) {
}
/* Try to encode a string object in order to save space. */
#define REDIS_ENCODING_LZF_MAX_SIZE (1024*64)
#define REDIS_ENCODING_LZF_MAX_COMPR_SIZE (1024*32)
#define LZF_COMPR_STATIC_BUF (1024*32)
robj
*
tryObjectEncoding
(
robj
*
o
)
{
long
value
;
sds
s
=
o
->
ptr
;
...
...
@@ -398,18 +397,23 @@ robj *tryObjectEncoding(robj *o) {
return
emb
;
}
/* Try LZF compression for objects up to
REDIS_ENCODING_LZF_MAX_SIZE
/* Try LZF compression for objects up to
server.mem_compression_max_size
* and greater than REDIS_ENCODING_EMBSTR_SIZE_LIMIT. */
if
(
server
.
mem_compression
&&
len
<=
REDIS_ENCODING_LZF_MAX_SIZE
)
{
if
(
server
.
mem_compression
&&
len
<=
server
.
mem_compression_max_size
)
{
/* Allocate four more bytes in our buffer since we need to store
* the size of the compressed string as header. */
unsigned
char
compr
[
4
+
REDIS_ENCODING_LZF_MAX_COMPR_SIZE
];
unsigned
char
compr_static
[
LZF_COMPR_STATIC_BUF
];
unsigned
char
*
compr
=
compr_static
;
size_t
comprlen
,
outlen
;
/* Save want to save at least 25% of memory for this to make sense. */
outlen
=
len
-
4
-
(
len
/
4
);
if
(
outlen
>
REDIS_ENCODING_LZF_MAX_SIZE
)
outlen
=
REDIS_ENCODING_LZF_MAX_SIZE
;
/* Use an heap allocated buffer if the output is too big for our
* static buffer. We use the trick to directly allocating an empty
* SDS string so we can use it directly to create the object later. */
if
(
outlen
+
4
>
LZF_COMPR_STATIC_BUF
)
compr
=
(
unsigned
char
*
)
sdsnewlen
(
NULL
,
outlen
+
4
);
comprlen
=
lzf_compress
(
s
,
len
,
compr
+
4
,
outlen
);
if
(
comprlen
!=
0
)
{
/* Object successfully compressed within the required space. */
...
...
@@ -419,9 +423,17 @@ robj *tryObjectEncoding(robj *o) {
compr
[
3
]
=
(
len
>>
24
)
&
0xff
;
if
(
o
->
encoding
==
REDIS_ENCODING_RAW
)
sdsfree
(
o
->
ptr
);
o
->
encoding
=
REDIS_ENCODING_LZF
;
o
->
ptr
=
sdsnewlen
(
compr
,
comprlen
+
4
);
if
(
compr
==
compr_static
)
{
/* When compressing to the static buffer we have to
* generate the SDS string here. */
o
->
ptr
=
sdsnewlen
(
compr
,
comprlen
+
4
);
}
else
{
/* Already an SDS, use it. */
o
->
ptr
=
compr
;
}
return
o
;
}
if
(
compr
!=
compr_static
)
sdsfree
((
char
*
)
compr
);
}
/* We can't encode the object...
...
...
src/redis.c
浏览文件 @
a4961a9a
...
...
@@ -1398,6 +1398,7 @@ void initServerConfig() {
server
.
requirepass
=
NULL
;
server
.
rdb_compression
=
REDIS_DEFAULT_RDB_COMPRESSION
;
server
.
mem_compression
=
REDIS_DEFAULT_MEM_COMPRESSION
;
server
.
mem_compression_max_size
=
REDIS_DEFAULT_MEM_COMPRESSION_MAX_SIZE
;
server
.
rdb_checksum
=
REDIS_DEFAULT_RDB_CHECKSUM
;
server
.
stop_writes_on_bgsave_err
=
REDIS_DEFAULT_STOP_WRITES_ON_BGSAVE_ERROR
;
server
.
activerehashing
=
REDIS_DEFAULT_ACTIVE_REHASHING
;
...
...
src/redis.h
浏览文件 @
a4961a9a
...
...
@@ -108,6 +108,7 @@
#define REDIS_DEFAULT_STOP_WRITES_ON_BGSAVE_ERROR 1
#define REDIS_DEFAULT_RDB_COMPRESSION 1
#define REDIS_DEFAULT_MEM_COMPRESSION 0
#define REDIS_DEFAULT_MEM_COMPRESSION_MAX_SIZE (1024*64)
#define REDIS_DEFAULT_RDB_CHECKSUM 1
#define REDIS_DEFAULT_RDB_FILENAME "dump.rdb"
#define REDIS_DEFAULT_SLAVE_SERVE_STALE_DATA 1
...
...
@@ -812,6 +813,7 @@ struct redisServer {
size_t
zset_max_ziplist_entries
;
size_t
zset_max_ziplist_value
;
int
mem_compression
;
/* In memory LZF compression. */
size_t
mem_compression_max_size
;
/* Try to compress up to this size. */
time_t
unixtime
;
/* Unix time sampled every cron cycle. */
long
long
mstime
;
/* Like unixtime but in milliseconds. */
/* Pubsub */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录