Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xindoo
redis
提交
4ae5b5e1
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,发现更多精彩内容 >>
提交
4ae5b5e1
编写于
5月 01, 2011
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
pupulate the Lua global tables KEYS and ARGV before executing the script
上级
00b7541b
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
27 addition
and
0 deletion
+27
-0
src/scripting.c
src/scripting.c
+27
-0
未找到文件。
src/scripting.c
浏览文件 @
4ae5b5e1
...
...
@@ -110,9 +110,31 @@ void luaReplyToRedisReply(redisClient *c, lua_State *lua) {
lua_pop
(
lua
,
1
);
}
/* Set an array of Redis String Objects as a Lua array (table) stored into a
* global variable. */
void
luaSetGlobalArray
(
lua_State
*
lua
,
char
*
var
,
robj
**
elev
,
int
elec
)
{
int
j
;
lua_newtable
(
lua
);
for
(
j
=
0
;
j
<
elec
;
j
++
)
{
lua_pushlstring
(
lua
,(
char
*
)
elev
[
j
]
->
ptr
,
sdslen
(
elev
[
j
]
->
ptr
));
lua_rawseti
(
lua
,
-
2
,
j
+
1
);
}
lua_setglobal
(
lua
,
var
);
}
void
evalCommand
(
redisClient
*
c
)
{
lua_State
*
lua
=
server
.
lua
;
char
funcname
[
43
];
long
long
numkeys
;
/* Get the number of arguments that are keys */
if
(
getLongLongFromObjectOrReply
(
c
,
c
->
argv
[
2
],
&
numkeys
,
NULL
)
!=
REDIS_OK
)
return
;
if
(
numkeys
>
(
c
->
argc
-
3
))
{
addReplyError
(
c
,
"Number of keys can't be greater than number of args"
);
return
;
}
/* We obtain the script SHA1, then check if this function is already
* defined into the Lua state */
...
...
@@ -148,6 +170,11 @@ void evalCommand(redisClient *c) {
}
lua_getglobal
(
lua
,
funcname
);
}
/* Populate the argv and keys table accordingly to the arguments that
* EVAL received. */
luaSetGlobalArray
(
lua
,
"KEYS"
,
c
->
argv
+
3
,
numkeys
);
luaSetGlobalArray
(
lua
,
"ARGV"
,
c
->
argv
+
3
+
numkeys
,
c
->
argc
-
3
-
numkeys
);
/* At this point whatever this script was never seen before or if it was
* already defined, we can call it. We have zero arguments and expect
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录