Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xindoo
redis
提交
df26a0ae
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,发现更多精彩内容 >>
提交
df26a0ae
编写于
3月 10, 2011
作者:
P
Pieter Noordhuis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Encode sorted set after loading from dump
上级
255eebe2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
28 addition
and
10 deletion
+28
-10
src/rdb.c
src/rdb.c
+15
-0
src/redis.h
src/redis.h
+3
-0
src/t_zset.c
src/t_zset.c
+10
-10
未找到文件。
src/rdb.c
浏览文件 @
df26a0ae
...
...
@@ -756,11 +756,13 @@ robj *rdbLoadObject(int type, FILE *fp) {
}
else
if
(
type
==
REDIS_ZSET
)
{
/* Read list/set value */
size_t
zsetlen
;
size_t
maxelelen
=
0
;
zset
*
zs
;
if
((
zsetlen
=
rdbLoadLen
(
fp
,
NULL
))
==
REDIS_RDB_LENERR
)
return
NULL
;
o
=
createZsetObject
();
zs
=
o
->
ptr
;
/* Load every single element of the list/set */
while
(
zsetlen
--
)
{
robj
*
ele
;
...
...
@@ -770,10 +772,21 @@ robj *rdbLoadObject(int type, FILE *fp) {
if
((
ele
=
rdbLoadEncodedStringObject
(
fp
))
==
NULL
)
return
NULL
;
ele
=
tryObjectEncoding
(
ele
);
if
(
rdbLoadDoubleValue
(
fp
,
&
score
)
==
-
1
)
return
NULL
;
/* Don't care about integer-encoded strings. */
if
(
ele
->
encoding
==
REDIS_ENCODING_RAW
&&
sdslen
(
ele
->
ptr
)
>
maxelelen
)
maxelelen
=
sdslen
(
ele
->
ptr
);
znode
=
zslInsert
(
zs
->
zsl
,
score
,
ele
);
dictAdd
(
zs
->
dict
,
ele
,
&
znode
->
score
);
incrRefCount
(
ele
);
/* added to skiplist */
}
/* Convert *after* loading, since sorted sets are not stored ordered. */
if
(
zsetLength
(
o
)
<=
server
.
zset_max_ziplist_entries
&&
maxelelen
<=
server
.
zset_max_ziplist_value
)
zsetConvert
(
o
,
REDIS_ENCODING_ZIPLIST
);
}
else
if
(
type
==
REDIS_HASH
)
{
size_t
hashlen
;
...
...
@@ -861,6 +874,8 @@ robj *rdbLoadObject(int type, FILE *fp) {
case
REDIS_ZSET_ZIPLIST
:
o
->
type
=
REDIS_ZSET
;
o
->
encoding
=
REDIS_ENCODING_ZIPLIST
;
if
(
zsetLength
(
o
)
>
server
.
zset_max_ziplist_entries
)
zsetConvert
(
o
,
REDIS_ENCODING_RAW
);
break
;
default:
redisPanic
(
"Unknown enoding"
);
...
...
src/redis.h
浏览文件 @
df26a0ae
...
...
@@ -799,6 +799,9 @@ void backgroundRewriteDoneHandler(int exitcode, int bysignal);
zskiplist
*
zslCreate
(
void
);
void
zslFree
(
zskiplist
*
zsl
);
zskiplistNode
*
zslInsert
(
zskiplist
*
zsl
,
double
score
,
robj
*
obj
);
int
zzlInsert
(
robj
*
zobj
,
robj
*
ele
,
double
score
);
unsigned
int
zsetLength
(
robj
*
zobj
);
void
zsetConvert
(
robj
*
zobj
,
int
encoding
);
/* Core functions */
void
freeMemoryIfNeeded
(
void
);
...
...
src/t_zset.c
浏览文件 @
df26a0ae
...
...
@@ -715,7 +715,7 @@ unsigned long zzlDeleteRangeByRank(robj *zobj, unsigned int start, unsigned int
* Common sorted set API
*----------------------------------------------------------------------------*/
int
zs
Length
(
robj
*
zobj
)
{
unsigned
int
zset
Length
(
robj
*
zobj
)
{
int
length
=
-
1
;
if
(
zobj
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
length
=
zzlLength
(
zobj
->
ptr
);
...
...
@@ -727,7 +727,7 @@ int zsLength(robj *zobj) {
return
length
;
}
void
zsConvert
(
robj
*
zobj
,
int
encoding
)
{
void
zs
et
Convert
(
robj
*
zobj
,
int
encoding
)
{
zset
*
zs
;
zskiplistNode
*
node
,
*
next
;
robj
*
ele
;
...
...
@@ -873,9 +873,9 @@ void zaddGenericCommand(redisClient *c, int incr) {
* too long *before* executing zzlInsert. */
redisAssert
(
zzlInsert
(
zobj
,
ele
,
score
)
==
REDIS_OK
);
if
(
zzlLength
(
zobj
->
ptr
)
>
server
.
zset_max_ziplist_entries
)
zsConvert
(
zobj
,
REDIS_ENCODING_RAW
);
zs
et
Convert
(
zobj
,
REDIS_ENCODING_RAW
);
if
(
sdslen
(
ele
->
ptr
)
>
server
.
zset_max_ziplist_value
)
zsConvert
(
zobj
,
REDIS_ENCODING_RAW
);
zs
et
Convert
(
zobj
,
REDIS_ENCODING_RAW
);
signalModifiedKey
(
c
->
db
,
key
);
server
.
dirty
++
;
...
...
@@ -1042,7 +1042,7 @@ void zremrangebyrankCommand(redisClient *c) {
checkType
(
c
,
zobj
,
REDIS_ZSET
))
return
;
/* Sanitize indexes. */
llen
=
zsLength
(
zobj
);
llen
=
zs
et
Length
(
zobj
);
if
(
start
<
0
)
start
=
llen
+
start
;
if
(
end
<
0
)
end
=
llen
+
end
;
if
(
start
<
0
)
start
=
0
;
...
...
@@ -1598,10 +1598,10 @@ void zunionInterGenericCommand(redisClient *c, robj *dstkey, int op) {
/* Convert to ziplist when in limits. */
if
(
dstzset
->
zsl
->
length
<=
server
.
zset_max_ziplist_entries
&&
maxelelen
<=
server
.
zset_max_ziplist_value
)
zsConvert
(
dstobj
,
REDIS_ENCODING_ZIPLIST
);
zs
et
Convert
(
dstobj
,
REDIS_ENCODING_ZIPLIST
);
dbAdd
(
c
->
db
,
dstkey
,
dstobj
);
addReplyLongLong
(
c
,
zsLength
(
dstobj
));
addReplyLongLong
(
c
,
zs
et
Length
(
dstobj
));
if
(
!
touched
)
signalModifiedKey
(
c
->
db
,
dstkey
);
server
.
dirty
++
;
}
else
{
...
...
@@ -1642,7 +1642,7 @@ void zrangeGenericCommand(redisClient *c, int reverse) {
||
checkType
(
c
,
zobj
,
REDIS_ZSET
))
return
;
/* Sanitize indexes. */
llen
=
zsLength
(
zobj
);
llen
=
zs
et
Length
(
zobj
);
if
(
start
<
0
)
start
=
llen
+
start
;
if
(
end
<
0
)
end
=
llen
+
end
;
if
(
start
<
0
)
start
=
0
;
...
...
@@ -1926,7 +1926,7 @@ void zcardCommand(redisClient *c) {
if
((
zobj
=
lookupKeyReadOrReply
(
c
,
key
,
shared
.
czero
))
==
NULL
||
checkType
(
c
,
zobj
,
REDIS_ZSET
))
return
;
addReplyLongLong
(
c
,
zsLength
(
zobj
));
addReplyLongLong
(
c
,
zs
et
Length
(
zobj
));
}
void
zscoreCommand
(
redisClient
*
c
)
{
...
...
@@ -1968,7 +1968,7 @@ void zrankGenericCommand(redisClient *c, int reverse) {
if
((
zobj
=
lookupKeyReadOrReply
(
c
,
key
,
shared
.
nullbulk
))
==
NULL
||
checkType
(
c
,
zobj
,
REDIS_ZSET
))
return
;
llen
=
zsLength
(
zobj
);
llen
=
zs
et
Length
(
zobj
);
redisAssert
(
ele
->
encoding
==
REDIS_ENCODING_RAW
);
if
(
zobj
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录