Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xindoo
redis
提交
39191553
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,发现更多精彩内容 >>
提交
39191553
编写于
3月 03, 2010
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
initial implementation of SUBSTR
上级
9693e4f0
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
42 addition
and
0 deletion
+42
-0
redis-cli.c
redis-cli.c
+1
-0
redis.c
redis.c
+41
-0
未找到文件。
redis-cli.c
浏览文件 @
39191553
...
...
@@ -65,6 +65,7 @@ static struct redisCommand cmdTable[] = {
{
"set"
,
3
,
REDIS_CMD_BULK
},
{
"setnx"
,
3
,
REDIS_CMD_BULK
},
{
"append"
,
3
,
REDIS_CMD_BULK
},
{
"substr"
,
4
,
REDIS_CMD_INLINE
},
{
"del"
,
-
2
,
REDIS_CMD_INLINE
},
{
"exists"
,
2
,
REDIS_CMD_INLINE
},
{
"incr"
,
2
,
REDIS_CMD_INLINE
},
...
...
redis.c
浏览文件 @
39191553
...
...
@@ -659,6 +659,7 @@ static void discardCommand(redisClient *c);
static
void
blpopCommand
(
redisClient
*
c
);
static
void
brpopCommand
(
redisClient
*
c
);
static
void
appendCommand
(
redisClient
*
c
);
static
void
substrCommand
(
redisClient
*
c
);
static
void
zrankCommand
(
redisClient
*
c
);
/*================================= Globals ================================= */
...
...
@@ -670,6 +671,7 @@ static struct redisCommand cmdTable[] = {
{
"set"
,
setCommand
,
3
,
REDIS_CMD_BULK
|
REDIS_CMD_DENYOOM
,
0
,
0
,
0
},
{
"setnx"
,
setnxCommand
,
3
,
REDIS_CMD_BULK
|
REDIS_CMD_DENYOOM
,
0
,
0
,
0
},
{
"append"
,
appendCommand
,
3
,
REDIS_CMD_BULK
|
REDIS_CMD_DENYOOM
,
1
,
1
,
1
},
{
"substr"
,
substrCommand
,
4
,
REDIS_CMD_INLINE
,
1
,
1
,
1
},
{
"del"
,
delCommand
,
-
2
,
REDIS_CMD_INLINE
,
0
,
0
,
0
},
{
"exists"
,
existsCommand
,
2
,
REDIS_CMD_INLINE
,
1
,
1
,
1
},
{
"incr"
,
incrCommand
,
2
,
REDIS_CMD_INLINE
|
REDIS_CMD_DENYOOM
,
1
,
1
,
1
},
...
...
@@ -3764,6 +3766,45 @@ static void appendCommand(redisClient *c) {
addReplySds
(
c
,
sdscatprintf
(
sdsempty
(),
":%lu
\r\n
"
,(
unsigned
long
)
totlen
));
}
static
void
substrCommand
(
redisClient
*
c
)
{
robj
*
o
;
long
start
=
atoi
(
c
->
argv
[
2
]
->
ptr
);
long
end
=
atoi
(
c
->
argv
[
3
]
->
ptr
);
o
=
lookupKeyRead
(
c
->
db
,
c
->
argv
[
1
]);
if
(
o
==
NULL
)
{
addReply
(
c
,
shared
.
nullbulk
);
}
else
{
if
(
o
->
type
!=
REDIS_STRING
)
{
addReply
(
c
,
shared
.
wrongtypeerr
);
}
else
{
size_t
rangelen
,
strlen
=
sdslen
(
o
->
ptr
);
sds
range
;
/* convert negative indexes */
if
(
start
<
0
)
start
=
strlen
+
start
;
if
(
end
<
0
)
end
=
strlen
+
end
;
if
(
start
<
0
)
start
=
0
;
if
(
end
<
0
)
end
=
0
;
/* indexes sanity checks */
if
(
start
>
end
||
(
size_t
)
start
>=
strlen
)
{
/* Out of range start or start > end result in null reply */
addReply
(
c
,
shared
.
nullbulk
);
return
;
}
if
((
size_t
)
end
>=
strlen
)
end
=
strlen
-
1
;
rangelen
=
(
end
-
start
)
+
1
;
/* Return the result */
addReplySds
(
c
,
sdscatprintf
(
sdsempty
(),
"$%lu
\r\n
"
,
rangelen
));
range
=
sdsnewlen
((
char
*
)
o
->
ptr
+
start
,
rangelen
);
addReplySds
(
c
,
range
);
addReply
(
c
,
shared
.
crlf
);
}
}
}
/* ========================= Type agnostic commands ========================= */
static
void
delCommand
(
redisClient
*
c
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录