Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
想上天的蜗牛@
redis
提交
8f8eeffe
R
redis
项目概览
想上天的蜗牛@
/
redis
与 Fork 源项目一致
从无法访问的项目Fork
通知
4
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,发现更多精彩内容 >>
提交
8f8eeffe
编写于
12月 15, 2010
作者:
P
Pieter Noordhuis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Disable negative offsets for SETRANGE
上级
e983cf34
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
7 addition
and
44 deletion
+7
-44
src/t_string.c
src/t_string.c
+5
-12
tests/unit/basic.tcl
tests/unit/basic.tcl
+2
-32
未找到文件。
src/t_string.c
浏览文件 @
8f8eeffe
...
...
@@ -195,11 +195,13 @@ void setrangeCommand(redisClient *c) {
if
(
getLongFromObjectOrReply
(
c
,
c
->
argv
[
2
],
&
offset
,
NULL
)
!=
REDIS_OK
)
return
;
if
(
offset
<
0
)
{
addReplyError
(
c
,
"offset is out of range"
);
return
;
}
o
=
lookupKeyWrite
(
c
->
db
,
c
->
argv
[
1
]);
if
(
o
==
NULL
)
{
/* Negative offset is always 0 for non-existing keys */
if
(
offset
<
0
)
offset
=
0
;
/* Return 0 when setting nothing on a non-existing string */
if
(
sdslen
(
value
)
==
0
)
{
addReply
(
c
,
shared
.
czero
);
...
...
@@ -233,15 +235,6 @@ void setrangeCommand(redisClient *c) {
return
;
}
/* Convert negative indexes. Note that for SETRANGE, the meaning of a
* negative index is a little different than for other commands.
* Here, an offset of -1 points to the trailing NULL byte of the
* string instead of the last character. */
if
(
offset
<
0
)
{
offset
=
olen
+
1
+
offset
;
if
(
offset
<
0
)
offset
=
0
;
}
/* Return when the resulting string exceeds allowed size */
if
(
checkStringLength
(
c
,
offset
+
sdslen
(
value
))
!=
REDIS_OK
)
return
;
...
...
tests/unit/basic.tcl
浏览文件 @
8f8eeffe
...
...
@@ -489,14 +489,6 @@ start_server {tags {"basic"}} {
r del mykey
assert_equal 4
[
r setrange mykey 1 foo
]
assert_equal
"
\000
foo"
[
r get mykey
]
r del mykey
assert_equal 3
[
r setrange mykey -1 foo
]
assert_equal
"foo"
[
r get mykey
]
r del mykey
assert_equal 3
[
r setrange mykey -100 foo
]
assert_equal
"foo"
[
r get mykey
]
}
test
"SETRANGE against string-encoded key"
{
...
...
@@ -512,18 +504,6 @@ start_server {tags {"basic"}} {
assert_equal 3
[
r setrange mykey 1 b
]
assert_equal
"fbo"
[
r get mykey
]
r set mykey
"foo"
assert_equal 6
[
r setrange mykey -1 bar
]
assert_equal
"foobar"
[
r get mykey
]
r set mykey
"foo"
assert_equal 5
[
r setrange mykey -2 bar
]
assert_equal
"fobar"
[
r get mykey
]
r set mykey
"foo"
assert_equal 3
[
r setrange mykey -20 bar
]
assert_equal
"bar"
[
r get mykey
]
r set mykey
"foo"
assert_equal 7
[
r setrange mykey 4 bar
]
assert_equal
"foo
\000
bar"
[
r get mykey
]
...
...
@@ -549,18 +529,6 @@ start_server {tags {"basic"}} {
assert_encoding raw mykey
assert_equal 1334
[
r get mykey
]
r set mykey 1234
assert_encoding int mykey
assert_equal 5
[
r setrange mykey -1 5
]
assert_encoding raw mykey
assert_equal 12345
[
r get mykey
]
r set mykey 1234
assert_encoding int mykey
assert_equal 4
[
r setrange mykey -2 5
]
assert_encoding raw mykey
assert_equal 1235
[
r get mykey
]
r set mykey 1234
assert_encoding int mykey
assert_equal 6
[
r setrange mykey 5 2
]
...
...
@@ -577,7 +545,9 @@ start_server {tags {"basic"}} {
test
"SETRANGE with out of range offset"
{
r del mykey
assert_error
"*maximum allowed size*"
{
r setrange mykey
[
expr 512*1024*1024-4
]
world
}
r set mykey
"hello"
assert_error
"*out of range*"
{
r setrange mykey -1 world
}
assert_error
"*maximum allowed size*"
{
r setrange mykey
[
expr 512*1024*1024-4
]
world
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录