Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
hanoi2005
redis
提交
7236fdb2
R
redis
项目概览
hanoi2005
/
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,发现更多精彩内容 >>
提交
7236fdb2
编写于
10月 13, 2010
作者:
P
Pieter Noordhuis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Return error when min and/or max in the sorted set range spec is not a double
上级
91504b6c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
30 addition
and
7 deletion
+30
-7
src/t_zset.c
src/t_zset.c
+18
-7
tests/unit/type/zset.tcl
tests/unit/type/zset.tcl
+12
-0
未找到文件。
src/t_zset.c
浏览文件 @
7236fdb2
...
...
@@ -307,7 +307,8 @@ zskiplistNode* zslistTypeGetElementByRank(zskiplist *zsl, unsigned long rank) {
}
/* Populate the rangespec according to the objects min and max. */
int
zslParseRange
(
robj
*
min
,
robj
*
max
,
zrangespec
*
spec
)
{
static
int
zslParseRange
(
robj
*
min
,
robj
*
max
,
zrangespec
*
spec
)
{
char
*
eptr
;
spec
->
minex
=
spec
->
maxex
=
0
;
/* Parse the min-max interval. If one of the values is prefixed
...
...
@@ -318,20 +319,24 @@ int zslParseRange(robj *min, robj *max, zrangespec *spec) {
spec
->
min
=
(
long
)
min
->
ptr
;
}
else
{
if
(((
char
*
)
min
->
ptr
)[
0
]
==
'('
)
{
spec
->
min
=
strtod
((
char
*
)
min
->
ptr
+
1
,
NULL
);
spec
->
min
=
strtod
((
char
*
)
min
->
ptr
+
1
,
&
eptr
);
if
(
eptr
[
0
]
!=
'\0'
||
isnan
(
spec
->
min
))
return
REDIS_ERR
;
spec
->
minex
=
1
;
}
else
{
spec
->
min
=
strtod
((
char
*
)
min
->
ptr
,
NULL
);
spec
->
min
=
strtod
((
char
*
)
min
->
ptr
,
&
eptr
);
if
(
eptr
[
0
]
!=
'\0'
||
isnan
(
spec
->
min
))
return
REDIS_ERR
;
}
}
if
(
max
->
encoding
==
REDIS_ENCODING_INT
)
{
spec
->
max
=
(
long
)
max
->
ptr
;
}
else
{
if
(((
char
*
)
max
->
ptr
)[
0
]
==
'('
)
{
spec
->
max
=
strtod
((
char
*
)
max
->
ptr
+
1
,
NULL
);
spec
->
max
=
strtod
((
char
*
)
max
->
ptr
+
1
,
&
eptr
);
if
(
eptr
[
0
]
!=
'\0'
||
isnan
(
spec
->
max
))
return
REDIS_ERR
;
spec
->
maxex
=
1
;
}
else
{
spec
->
max
=
strtod
((
char
*
)
max
->
ptr
,
NULL
);
spec
->
max
=
strtod
((
char
*
)
max
->
ptr
,
&
eptr
);
if
(
eptr
[
0
]
!=
'\0'
||
isnan
(
spec
->
max
))
return
REDIS_ERR
;
}
}
...
...
@@ -481,7 +486,10 @@ void zremrangebyscoreCommand(redisClient *c) {
zset
*
zs
;
/* Parse the range arguments. */
zslParseRange
(
c
->
argv
[
2
],
c
->
argv
[
3
],
&
range
);
if
(
zslParseRange
(
c
->
argv
[
2
],
c
->
argv
[
3
],
&
range
)
!=
REDIS_OK
)
{
addReplyError
(
c
,
"min or max is not a double"
);
return
;
}
if
((
o
=
lookupKeyWriteOrReply
(
c
,
c
->
argv
[
1
],
shared
.
czero
))
==
NULL
||
checkType
(
c
,
o
,
REDIS_ZSET
))
return
;
...
...
@@ -838,7 +846,10 @@ void genericZrangebyscoreCommand(redisClient *c, int reverse, int justcount) {
void
*
replylen
=
NULL
;
/* Parse the range arguments. */
zslParseRange
(
c
->
argv
[
2
],
c
->
argv
[
3
],
&
range
);
if
(
zslParseRange
(
c
->
argv
[
2
],
c
->
argv
[
3
],
&
range
)
!=
REDIS_OK
)
{
addReplyError
(
c
,
"min or max is not a double"
);
return
;
}
/* Parse optional extra arguments. Note that ZCOUNT will exactly have
* 4 arguments, so we'll never enter the following code path. */
...
...
tests/unit/type/zset.tcl
浏览文件 @
7236fdb2
...
...
@@ -253,6 +253,12 @@ start_server {tags {"zset"}} {
assert_equal
{
d 3 c 2
}
[
r zrevrangebyscore zset 5 2 LIMIT 2 3 WITHSCORES
]
}
test
"ZRANGEBYSCORE with non-value min or max"
{
assert_error
"*not a double*"
{
r zrangebyscore fooz str 1
}
assert_error
"*not a double*"
{
r zrangebyscore fooz 1 str
}
assert_error
"*not a double*"
{
r zrangebyscore fooz 1 NaN
}
}
tags
{
"slow"
}
{
test
{
ZRANGEBYSCORE fuzzy test, 100 ranges in 1000 elements sorted set
}
{
set err
{}
...
...
@@ -386,6 +392,12 @@ start_server {tags {"zset"}} {
assert_equal
{
a e
}
[
r zrange zset 0 -1
]
}
test
"ZREMRANGEBYSCORE with non-value min or max"
{
assert_error
"*not a double*"
{
r zremrangebyscore fooz str 1
}
assert_error
"*not a double*"
{
r zremrangebyscore fooz 1 str
}
assert_error
"*not a double*"
{
r zremrangebyscore fooz 1 NaN
}
}
test
"ZREMRANGEBYRANK basics"
{
proc remrangebyrank
{
min max
}
{
create_zset zset
{
1 a 2 b 3 c 4 d 5 e
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录