Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Turbo码先生
redis
提交
9fc47ddf
R
redis
项目概览
Turbo码先生
/
redis
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
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,发现更多精彩内容 >>
提交
9fc47ddf
编写于
6月 22, 2015
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Geo: zsetScore refactoring
Now used both in geo.c and t_zset to provide ZSCORE.
上级
575e247a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
24 addition
and
43 deletion
+24
-43
src/redis.h
src/redis.h
+1
-0
src/t_zset.c
src/t_zset.c
+23
-18
src/zset.c
src/zset.c
+0
-24
src/zset.h
src/zset.h
+0
-1
未找到文件。
src/redis.h
浏览文件 @
9fc47ddf
...
...
@@ -1240,6 +1240,7 @@ void zzlNext(unsigned char *zl, unsigned char **eptr, unsigned char **sptr);
void
zzlPrev
(
unsigned
char
*
zl
,
unsigned
char
**
eptr
,
unsigned
char
**
sptr
);
unsigned
int
zsetLength
(
robj
*
zobj
);
void
zsetConvert
(
robj
*
zobj
,
int
encoding
);
int
zsetScore
(
robj
*
zobj
,
robj
*
member
,
double
*
score
);
unsigned
long
zslGetRank
(
zskiplist
*
zsl
,
double
score
,
robj
*
o
);
/* Core functions */
...
...
src/t_zset.c
浏览文件 @
9fc47ddf
...
...
@@ -1166,6 +1166,26 @@ void zsetConvert(robj *zobj, int encoding) {
}
}
/* Return (by reference) the score of the specified member of the sorted set
* storing it into *score. If the element does not exist REDIS_ERR is returned
* otherwise REDIS_OK is returned and *score is correctly populated.
* If 'zobj' or 'member' is NULL, REDIS_ERR is returned. */
int
zsetScore
(
robj
*
zobj
,
robj
*
member
,
double
*
score
)
{
if
(
!
zobj
||
!
member
)
return
REDIS_ERR
;
if
(
zobj
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
if
(
zzlFind
(
zobj
->
ptr
,
member
,
score
)
==
NULL
)
return
REDIS_ERR
;
}
else
if
(
zobj
->
encoding
==
REDIS_ENCODING_SKIPLIST
)
{
zset
*
zs
=
zobj
->
ptr
;
dictEntry
*
de
=
dictFind
(
zs
->
dict
,
member
);
if
(
de
==
NULL
)
return
REDIS_ERR
;
*
score
=
*
(
double
*
)
dictGetVal
(
de
);
}
else
{
redisPanic
(
"Unknown sorted set encoding"
);
}
return
REDIS_OK
;
}
/*-----------------------------------------------------------------------------
* Sorted set commands
*----------------------------------------------------------------------------*/
...
...
@@ -2815,25 +2835,10 @@ void zscoreCommand(redisClient *c) {
if
((
zobj
=
lookupKeyReadOrReply
(
c
,
key
,
shared
.
nullbulk
))
==
NULL
||
checkType
(
c
,
zobj
,
REDIS_ZSET
))
return
;
if
(
zobj
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
if
(
zzlFind
(
zobj
->
ptr
,
c
->
argv
[
2
],
&
score
)
!=
NULL
)
addReplyDouble
(
c
,
score
);
else
addReply
(
c
,
shared
.
nullbulk
);
}
else
if
(
zobj
->
encoding
==
REDIS_ENCODING_SKIPLIST
)
{
zset
*
zs
=
zobj
->
ptr
;
dictEntry
*
de
;
c
->
argv
[
2
]
=
tryObjectEncoding
(
c
->
argv
[
2
]);
de
=
dictFind
(
zs
->
dict
,
c
->
argv
[
2
]);
if
(
de
!=
NULL
)
{
score
=
*
(
double
*
)
dictGetVal
(
de
);
addReplyDouble
(
c
,
score
);
}
else
{
addReply
(
c
,
shared
.
nullbulk
);
}
if
(
zsetScore
(
zobj
,
c
->
argv
[
2
],
&
score
)
==
REDIS_ERR
)
{
addReply
(
c
,
shared
.
nullbulk
);
}
else
{
redisPanic
(
"Unknown sorted set encoding"
);
addReplyDouble
(
c
,
score
);
}
}
...
...
src/zset.c
浏览文件 @
9fc47ddf
...
...
@@ -12,30 +12,6 @@ int zslValueLteMax(double value, zrangespec *spec);
* Direct Redis DB Interaction
* ==================================================================== */
/* zset access is mostly a copy/paste from zscoreCommand() */
int
zsetScore
(
robj
*
zobj
,
robj
*
member
,
double
*
score
)
{
if
(
!
zobj
||
!
member
)
return
0
;
if
(
zobj
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
if
(
zzlFind
(
zobj
->
ptr
,
member
,
score
)
==
NULL
)
return
0
;
}
else
if
(
zobj
->
encoding
==
REDIS_ENCODING_SKIPLIST
)
{
zset
*
zs
=
zobj
->
ptr
;
dictEntry
*
de
;
member
=
tryObjectEncoding
(
member
);
de
=
dictFind
(
zs
->
dict
,
member
);
if
(
de
!=
NULL
)
{
*
score
=
*
(
double
*
)
dictGetVal
(
de
);
}
else
return
0
;
}
else
{
return
0
;
}
return
1
;
}
/* Largely extracted from genericZrangebyscoreCommand() in t_zset.c */
/* The zrangebyscoreCommand expects to only operate on a live redisClient,
* but we need results returned to us, not sent over an async socket. */
...
...
src/zset.h
浏览文件 @
9fc47ddf
...
...
@@ -16,7 +16,6 @@ struct zipresult {
};
/* Redis DB Access */
int
zsetScore
(
robj
*
zobj
,
robj
*
member
,
double
*
score
);
list
*
geozrangebyscore
(
robj
*
zobj
,
double
min
,
double
max
,
int
limit
);
/* New list operation: append one list to another */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录