Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
别团等shy哥发育
redis
提交
d1c920c5
R
redis
项目概览
别团等shy哥发育
/
redis
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
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,发现更多精彩内容 >>
提交
d1c920c5
编写于
3月 09, 2011
作者:
P
Pieter Noordhuis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support dual encoding for more commands
上级
aff255c8
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
79 addition
and
42 deletion
+79
-42
src/t_zset.c
src/t_zset.c
+79
-42
未找到文件。
src/t_zset.c
浏览文件 @
d1c920c5
...
...
@@ -658,7 +658,7 @@ int zzlInsert(robj *zobj, robj *ele, double score) {
break
;
}
else
if
(
s
==
score
)
{
/* Ensure lexicographical ordering for elements. */
if
(
zzlCompareElements
(
eptr
,
ele
->
ptr
,
sdslen
(
ele
->
ptr
))
<
0
)
{
if
(
zzlCompareElements
(
eptr
,
ele
->
ptr
,
sdslen
(
ele
->
ptr
))
>
0
)
{
zzlInsertAt
(
zobj
,
ele
,
score
,
eptr
);
break
;
}
...
...
@@ -1505,66 +1505,103 @@ void zcountCommand(redisClient *c) {
}
void
zcardCommand
(
redisClient
*
c
)
{
robj
*
o
;
zset
*
zs
;
robj
*
key
=
c
->
argv
[
1
]
;
robj
*
zobj
;
if
((
o
=
lookupKeyReadOrReply
(
c
,
c
->
argv
[
1
]
,
shared
.
czero
))
==
NULL
||
checkType
(
c
,
o
,
REDIS_ZSET
))
return
;
if
((
zobj
=
lookupKeyReadOrReply
(
c
,
key
,
shared
.
czero
))
==
NULL
||
checkType
(
c
,
zobj
,
REDIS_ZSET
))
return
;
zs
=
o
->
ptr
;
addReplyLongLong
(
c
,
zs
->
zsl
->
length
);
addReplyLongLong
(
c
,
zzlLength
(
zobj
));
}
void
zscoreCommand
(
redisClient
*
c
)
{
robj
*
o
;
zset
*
zs
;
d
ictEntry
*
d
e
;
robj
*
key
=
c
->
argv
[
1
]
;
robj
*
zobj
;
d
ouble
scor
e
;
if
((
o
=
lookupKeyReadOrReply
(
c
,
c
->
argv
[
1
]
,
shared
.
nullbulk
))
==
NULL
||
checkType
(
c
,
o
,
REDIS_ZSET
))
return
;
if
((
zobj
=
lookupKeyReadOrReply
(
c
,
key
,
shared
.
nullbulk
))
==
NULL
||
checkType
(
c
,
zobj
,
REDIS_ZSET
))
return
;
zs
=
o
->
ptr
;
c
->
argv
[
2
]
=
tryObjectEncoding
(
c
->
argv
[
2
]);
de
=
dictFind
(
zs
->
dict
,
c
->
argv
[
2
]);
if
(
!
de
)
{
addReply
(
c
,
shared
.
nullbulk
);
}
else
{
double
*
score
=
dictGetEntryVal
(
de
);
if
(
zobj
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
if
(
zzlFind
(
zobj
,
c
->
argv
[
2
],
&
score
)
!=
NULL
)
addReplyDouble
(
c
,
score
);
else
addReply
(
c
,
shared
.
nullbulk
);
}
else
if
(
zobj
->
encoding
==
REDIS_ENCODING_RAW
)
{
zset
*
zs
=
zobj
->
ptr
;
dictEntry
*
de
;
addReplyDouble
(
c
,
*
score
);
c
->
argv
[
2
]
=
tryObjectEncoding
(
c
->
argv
[
2
]);
de
=
dictFind
(
zs
->
dict
,
c
->
argv
[
2
]);
if
(
de
!=
NULL
)
{
score
=
*
(
double
*
)
dictGetEntryVal
(
de
);
addReplyDouble
(
c
,
score
);
}
else
{
addReply
(
c
,
shared
.
nullbulk
);
}
}
else
{
redisPanic
(
"Unknown sorted set encoding"
);
}
}
void
zrankGenericCommand
(
redisClient
*
c
,
int
reverse
)
{
robj
*
o
;
zset
*
zs
;
zskiplist
*
zsl
;
dictEntry
*
de
;
robj
*
key
=
c
->
argv
[
1
]
;
robj
*
ele
=
c
->
argv
[
2
]
;
robj
*
zobj
;
unsigned
long
llen
;
unsigned
long
rank
;
double
*
score
;
if
((
o
=
lookupKeyReadOrReply
(
c
,
c
->
argv
[
1
],
shared
.
nullbulk
))
==
NULL
||
checkType
(
c
,
o
,
REDIS_ZSET
))
return
;
if
((
zobj
=
lookupKeyReadOrReply
(
c
,
key
,
shared
.
nullbulk
))
==
NULL
||
checkType
(
c
,
zobj
,
REDIS_ZSET
))
return
;
llen
=
zsLength
(
zobj
);
zs
=
o
->
ptr
;
zsl
=
zs
->
zsl
;
c
->
argv
[
2
]
=
tryObjectEncoding
(
c
->
argv
[
2
]);
de
=
dictFind
(
zs
->
dict
,
c
->
argv
[
2
]);
if
(
!
de
)
{
addReply
(
c
,
shared
.
nullbulk
);
return
;
}
redisAssert
(
ele
->
encoding
==
REDIS_ENCODING_RAW
);
if
(
zobj
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
unsigned
char
*
zl
=
zobj
->
ptr
;
unsigned
char
*
eptr
,
*
sptr
;
score
=
dictGetEntryVal
(
de
);
rank
=
zslGetRank
(
zsl
,
*
score
,
c
->
argv
[
2
]);
if
(
rank
)
{
if
(
reverse
)
{
addReplyLongLong
(
c
,
zsl
->
length
-
rank
);
eptr
=
ziplistIndex
(
zl
,
0
);
redisAssert
(
eptr
!=
NULL
);
sptr
=
ziplistNext
(
zl
,
eptr
);
redisAssert
(
sptr
!=
NULL
);
rank
=
1
;
while
(
eptr
!=
NULL
)
{
if
(
ziplistCompare
(
eptr
,
ele
->
ptr
,
sdslen
(
ele
->
ptr
)))
break
;
rank
++
;
zzlNext
(
zl
,
&
eptr
,
&
sptr
);
}
if
(
eptr
!=
NULL
)
{
if
(
reverse
)
addReplyLongLong
(
c
,
llen
-
rank
);
else
addReplyLongLong
(
c
,
rank
-
1
);
}
else
{
addReplyLongLong
(
c
,
rank
-
1
);
addReply
(
c
,
shared
.
nullbulk
);
}
}
else
if
(
zobj
->
encoding
==
REDIS_ENCODING_RAW
)
{
zset
*
zs
=
zobj
->
ptr
;
zskiplist
*
zsl
=
zs
->
zsl
;
dictEntry
*
de
;
double
score
;
ele
=
c
->
argv
[
2
]
=
tryObjectEncoding
(
c
->
argv
[
2
]);
de
=
dictFind
(
zs
->
dict
,
ele
);
if
(
de
!=
NULL
)
{
score
=
*
(
double
*
)
dictGetEntryVal
(
de
);
rank
=
zslGetRank
(
zsl
,
score
,
ele
);
redisAssert
(
rank
);
/* Existing elements always have a rank. */
if
(
reverse
)
addReplyLongLong
(
c
,
llen
-
rank
);
else
addReplyLongLong
(
c
,
rank
-
1
);
}
else
{
addReply
(
c
,
shared
.
nullbulk
);
}
}
else
{
addReply
(
c
,
shared
.
nullbulk
);
redisPanic
(
"Unknown sorted set encoding"
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录