Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xindoo
redis
提交
070e3945
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,发现更多精彩内容 >>
提交
070e3945
编写于
10月 24, 2011
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SCRIPT command for introspection and control of the scripting environment.
上级
ca1f766a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
51 addition
and
4 deletion
+51
-4
src/redis.c
src/redis.c
+3
-1
src/redis.h
src/redis.h
+1
-0
src/scripting.c
src/scripting.c
+47
-3
未找到文件。
src/redis.c
浏览文件 @
070e3945
...
...
@@ -215,7 +215,8 @@ struct redisCommand redisCommandTable[] = {
{
"client"
,
clientCommand
,
-
2
,
"ar"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"eval"
,
evalCommand
,
-
3
,
"wms"
,
0
,
zunionInterGetKeys
,
0
,
0
,
0
,
0
,
0
},
{
"evalsha"
,
evalShaCommand
,
-
3
,
"wms"
,
0
,
zunionInterGetKeys
,
0
,
0
,
0
,
0
,
0
},
{
"slowlog"
,
slowlogCommand
,
-
2
,
"r"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
}
{
"slowlog"
,
slowlogCommand
,
-
2
,
"r"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"script"
,
scriptCommand
,
-
2
,
"ras"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
}
};
/*============================ Utility functions ============================ */
...
...
@@ -869,6 +870,7 @@ void initServerConfig() {
server
.
cluster_enabled
=
0
;
server
.
cluster
.
configfile
=
zstrdup
(
"nodes.conf"
);
server
.
lua_time_limit
=
REDIS_LUA_TIME_LIMIT
;
server
.
lua_client
=
NULL
;
updateLRUClock
();
resetServerSaveParams
();
...
...
src/redis.h
浏览文件 @
070e3945
...
...
@@ -1128,6 +1128,7 @@ void objectCommand(redisClient *c);
void
clientCommand
(
redisClient
*
c
);
void
evalCommand
(
redisClient
*
c
);
void
evalShaCommand
(
redisClient
*
c
);
void
scriptCommand
(
redisClient
*
c
);
#if defined(__GNUC__)
void
*
calloc
(
size_t
count
,
size_t
size
)
__attribute__
((
deprecated
));
...
...
src/scripting.c
浏览文件 @
070e3945
...
...
@@ -304,6 +304,10 @@ void luaLoadLibraries(lua_State *lua) {
#endif
}
/* Initialize the scripting environment.
* It is possible to call this function to reset the scripting environment
* assuming that we call scriptingRelease() before.
* See scriptingReset() for more information. */
void
scriptingInit
(
void
)
{
lua_State
*
lua
=
lua_open
();
luaLoadLibraries
(
lua
);
...
...
@@ -364,13 +368,29 @@ void scriptingInit(void) {
lua_setglobal
(
lua
,
"math"
);
/* Create the (non connected) client that we use to execute Redis commands
* inside the Lua interpreter */
server
.
lua_client
=
createClient
(
-
1
);
server
.
lua_client
->
flags
|=
REDIS_LUA_CLIENT
;
* inside the Lua interpreter.
* Note: there is no need to create it again when this function is called
* by scriptingReset(). */
if
(
server
.
lua_client
==
NULL
)
{
server
.
lua_client
=
createClient
(
-
1
);
server
.
lua_client
->
flags
|=
REDIS_LUA_CLIENT
;
}
server
.
lua
=
lua
;
}
/* Release resources related to Lua scripting.
* This function is used in order to reset the scripting environment. */
void
scriptingRelease
(
void
)
{
dictRelease
(
server
.
lua_scripts
);
lua_close
(
server
.
lua
);
}
void
scriptingReset
(
void
)
{
scriptingRelease
();
scriptingInit
();
}
/* Hash the scripit into a SHA1 digest. We use this as Lua function name.
* Digest should point to a 41 bytes buffer: 40 for SHA1 converted into an
* hexadecimal number, plus 1 byte for null term. */
...
...
@@ -669,3 +689,27 @@ int redis_math_randomseed (lua_State *L) {
redisSrand48
(
luaL_checkint
(
L
,
1
));
return
0
;
}
/* ---------------------------------------------------------------------------
* SCRIPT command for script environment introspection and control
* ------------------------------------------------------------------------- */
void
scriptCommand
(
redisClient
*
c
)
{
if
(
c
->
argc
==
2
&&
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"flush"
))
{
scriptingReset
();
addReply
(
c
,
shared
.
ok
);
server
.
dirty
++
;
/* Replicating this command is a good idea. */
}
else
if
(
c
->
argc
>=
2
&&
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"exists"
))
{
int
j
;
addReplyMultiBulkLen
(
c
,
c
->
argc
-
2
);
for
(
j
=
2
;
j
<
c
->
argc
;
j
++
)
{
if
(
dictFind
(
server
.
lua_scripts
,
c
->
argv
[
j
]
->
ptr
))
addReply
(
c
,
shared
.
cone
);
else
addReply
(
c
,
shared
.
czero
);
}
}
else
{
addReplyError
(
c
,
"Unknown SCRIPT subcommand or wrong # of args."
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录