Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
别团等shy哥发育
redis
提交
e8c993f0
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,发现更多精彩内容 >>
提交
e8c993f0
编写于
10月 25, 2011
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixes for the scripting refactoring and new commands. Tests for the new features.
上级
a9b07ac4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
38 addition
and
7 deletion
+38
-7
src/scripting.c
src/scripting.c
+11
-6
tests/unit/scripting.tcl
tests/unit/scripting.tcl
+27
-1
未找到文件。
src/scripting.c
浏览文件 @
e8c993f0
...
...
@@ -500,7 +500,6 @@ void luaSetGlobalArray(lua_State *lua, char *var, robj **elev, int elec) {
int
luaCreateFunction
(
redisClient
*
c
,
lua_State
*
lua
,
char
*
funcname
,
robj
*
body
)
{
sds
funcdef
=
sdsempty
();
lua_pop
(
lua
,
1
);
/* remove the nil from the stack */
funcdef
=
sdscat
(
funcdef
,
"function "
);
funcdef
=
sdscatlen
(
funcdef
,
funcname
,
42
);
funcdef
=
sdscatlen
(
funcdef
,
" ()
\n
"
,
4
);
...
...
@@ -581,12 +580,12 @@ void evalGenericCommand(redisClient *c, int evalsha) {
/* Try to lookup the Lua function */
lua_getglobal
(
lua
,
funcname
);
if
(
lua_isnil
(
lua
,
1
))
{
lua_pop
(
lua
,
1
);
/* remove the nil from the stack */
/* Function not defined... let's define it if we have the
* body of the funciton. If this is an EVALSHA call we can just
* return an error. */
if
(
evalsha
)
{
addReply
(
c
,
shared
.
noscripterr
);
lua_pop
(
lua
,
1
);
/* remove the nil from the stack */
return
;
}
if
(
luaCreateFunction
(
c
,
lua
,
funcname
,
c
->
argv
[
1
])
==
REDIS_ERR
)
return
;
...
...
@@ -724,15 +723,21 @@ void scriptCommand(redisClient *c) {
addReply
(
c
,
shared
.
czero
);
}
}
else
if
(
c
->
argc
==
3
&&
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"load"
))
{
/* We obtain the script SHA1, then check if this function is already
* defined into the Lua state */
char
funcname
[
43
];
sds
sha
;
funcname
[
0
]
=
'f'
;
funcname
[
1
]
=
'_'
;
hashScript
(
funcname
+
2
,
c
->
argv
[
2
]
->
ptr
,
sdslen
(
c
->
argv
[
2
]
->
ptr
));
if
(
luaCreateFunction
(
c
,
server
.
lua
,
funcname
,
c
->
argv
[
2
])
==
REDIS_ERR
)
return
;
sha
=
sdsnewlen
(
funcname
+
2
,
40
);
if
(
dictFind
(
server
.
lua_scripts
,
sha
)
==
NULL
)
{
if
(
luaCreateFunction
(
c
,
server
.
lua
,
funcname
,
c
->
argv
[
2
])
==
REDIS_ERR
)
{
sdsfree
(
sha
);
return
;
}
}
sdsfree
(
sha
);
addReply
(
c
,
shared
.
ok
);
}
else
{
addReplyError
(
c
,
"Unknown SCRIPT subcommand or wrong # of args."
);
...
...
tests/unit/scripting.tcl
浏览文件 @
e8c993f0
...
...
@@ -47,8 +47,13 @@ start_server {tags {"scripting"}} {
r evalsha 9bd632c7d33e571e9f24556ebed26c3479a87129 0
}
{
myval
}
test
{
EVALSHA - Do we get an error on invalid SHA1?
}
{
catch
{
r evalsha NotValidShaSUM 0
}
e
set _ $e
}
{
NOSCRIPT*
}
test
{
EVALSHA - Do we get an error on non defined SHA1?
}
{
catch
{
r evalsha ff
ffffffffffffffffffffffffffffffffffffff
0
}
e
catch
{
r evalsha ff
d632c7d33e571e9f24556ebed26c3479a87130
0
}
e
set _ $e
}
{
NOSCRIPT*
}
...
...
@@ -162,6 +167,27 @@ start_server {tags {"scripting"}} {
}
e
set e
}
{
*against a key*
}
test
{
SCRIPTING FLUSH - is able to clear the scripts cache?
}
{
r set mykey myval
set v
[
r evalsha 9bd632c7d33e571e9f24556ebed26c3479a87129 0
]
assert_equal $v myval
set e
""
r script flush
catch
{
r evalsha 9bd632c7d33e571e9f24556ebed26c3479a87129 0
}
e
set e
}
{
NOSCRIPT*
}
test
{
SCRIPT EXISTS - can detect already defined scripts?
}
{
r eval
"return 1+1"
0
r script exists a27e7e8a43702b7046d4f6a7ccf5b60cef6b9bd9 a27e7e8a43702b7046d4f6a7ccf5b60cef6b9bda
}
{
1 0
}
test
{
SCRIPT LOAD - is able to register scripts in the scripting cache
}
{
list
\
[
r script load
"return 'loaded'"
]
\
[
r evalsha b534286061d4b9e4026607613b95c06c06015ae8 0
]
}
{
OK loaded
}
}
start_server
{
tags
{
"scripting repl"
}}
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录