Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
hanoi2005
redis
提交
eeffcf38
R
redis
项目概览
hanoi2005
/
redis
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
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,发现更多精彩内容 >>
提交
eeffcf38
编写于
5月 06, 2011
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Lua scripts max execution time
上级
8c3402df
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
41 addition
and
0 deletion
+41
-0
redis.conf
redis.conf
+7
-0
src/config.c
src/config.c
+10
-0
src/redis.c
src/redis.c
+1
-0
src/redis.h
src/redis.h
+5
-0
src/scripting.c
src/scripting.c
+18
-0
未找到文件。
redis.conf
浏览文件 @
eeffcf38
...
...
@@ -292,6 +292,13 @@ appendfsync everysec
# "no" that is the safest pick from the point of view of durability.
no
-
appendfsync
-
on
-
rewrite
no
################################ LUA SCRIPTING ###############################
# Max execution time of a Lua script in milliseconds.
# This prevents that a programming error generating an infinite loop will block
# your server forever. Set it to 0 or a negative value for unlimited execution.
lua
-
time
-
limit
60000
#################################### DISK STORE ###############################
# When disk store is active Redis works as an on-disk database, where memory
...
...
src/config.c
浏览文件 @
eeffcf38
...
...
@@ -296,6 +296,8 @@ void loadServerConfig(char *filename) {
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"cluster-config-file"
)
&&
argc
==
2
)
{
zfree
(
server
.
cluster
.
configfile
);
server
.
cluster
.
configfile
=
zstrdup
(
argv
[
1
]);
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"lua-time-limit"
)
&&
argc
==
2
)
{
server
.
lua_time_limit
=
strtoll
(
argv
[
1
],
NULL
,
10
);
}
else
{
err
=
"Bad directive or wrong number of arguments"
;
goto
loaderr
;
}
...
...
@@ -460,6 +462,9 @@ void configSetCommand(redisClient *c) {
}
else
if
(
!
strcasecmp
(
c
->
argv
[
2
]
->
ptr
,
"zset-max-ziplist-value"
))
{
if
(
getLongLongFromObject
(
o
,
&
ll
)
==
REDIS_ERR
||
ll
<
0
)
goto
badfmt
;
server
.
zset_max_ziplist_value
=
ll
;
}
else
if
(
!
strcasecmp
(
c
->
argv
[
2
]
->
ptr
,
"lua-time-limit"
))
{
if
(
getLongLongFromObject
(
o
,
&
ll
)
==
REDIS_ERR
||
ll
<
0
)
goto
badfmt
;
server
.
lua_time_limit
=
ll
;
}
else
{
addReplyErrorFormat
(
c
,
"Unsupported CONFIG parameter: %s"
,
(
char
*
)
c
->
argv
[
2
]
->
ptr
);
...
...
@@ -621,6 +626,11 @@ void configGetCommand(redisClient *c) {
addReplyBulkLongLong
(
c
,
server
.
zset_max_ziplist_value
);
matches
++
;
}
if
(
stringmatch
(
pattern
,
"lua-time-limit"
,
0
))
{
addReplyBulkCString
(
c
,
"lua-time-limit"
);
addReplyBulkLongLong
(
c
,
server
.
lua_time_limit
);
matches
++
;
}
setDeferredMultiBulkLength
(
c
,
replylen
,
matches
*
2
);
}
...
...
src/redis.c
浏览文件 @
eeffcf38
...
...
@@ -858,6 +858,7 @@ void initServerConfig() {
server
.
cache_flush_delay
=
0
;
server
.
cluster_enabled
=
0
;
server
.
cluster
.
configfile
=
zstrdup
(
"nodes.conf"
);
server
.
lua_time_limit
=
REDIS_LUA_TIME_LIMIT
;
updateLRUClock
();
resetServerSaveParams
();
...
...
src/redis.h
浏览文件 @
eeffcf38
...
...
@@ -225,6 +225,9 @@
#define REDIS_BGSAVE_THREAD_DONE_OK 2
#define REDIS_BGSAVE_THREAD_DONE_ERR 3
/* Scripting */
#define REDIS_LUA_TIME_LIMIT 60000
/* milliseconds */
/* We can print the stacktrace, so our assert is defined this way: */
#define redisAssert(_e) ((_e)?(void)0 : (_redisAssert(#_e,__FILE__,__LINE__),_exit(1)))
#define redisPanic(_e) _redisPanic(#_e,__FILE__,__LINE__),_exit(1)
...
...
@@ -659,6 +662,8 @@ struct redisServer {
/* Scripting */
lua_State
*
lua
;
redisClient
*
lua_client
;
long
long
lua_time_limit
;
long
long
lua_time_start
;
};
typedef
struct
pubsubPattern
{
...
...
src/scripting.c
浏览文件 @
eeffcf38
...
...
@@ -199,6 +199,19 @@ int luaRedisCommand(lua_State *lua) {
return
1
;
}
void
luaMaskCountHook
(
lua_State
*
lua
,
lua_Debug
*
ar
)
{
long
long
elapsed
;
REDIS_NOTUSED
(
ar
);
if
(
server
.
lua_time_limit
<=
0
)
return
;
elapsed
=
(
ustime
()
/
1000
)
-
server
.
lua_time_start
;
if
(
elapsed
>=
server
.
lua_time_limit
)
{
lua_pushstring
(
lua
,
"Script aborted for max execution time..."
);
lua_error
(
lua
);
redisLog
(
REDIS_NOTICE
,
"Lua script aborted for max execution time after %lld milliseconds of running time"
,
elapsed
);
}
}
void
scriptingInit
(
void
)
{
lua_State
*
lua
=
lua_open
();
luaL_openlibs
(
lua
);
...
...
@@ -212,6 +225,10 @@ void scriptingInit(void) {
server
.
lua_client
=
createClient
(
-
1
);
server
.
lua_client
->
flags
|=
REDIS_LUA_CLIENT
;
/* Set an hook in order to be able to stop the script execution if it
* is running for too much time. */
lua_sethook
(
lua
,
luaMaskCountHook
,
LUA_MASKCOUNT
,
10000
);
server
.
lua
=
lua
;
}
...
...
@@ -375,6 +392,7 @@ void evalCommand(redisClient *c) {
/* 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
* a single return value. */
server
.
lua_time_start
=
ustime
()
/
1000
;
if
(
lua_pcall
(
lua
,
0
,
1
,
0
))
{
selectDb
(
c
,
server
.
lua_client
->
db
->
id
);
/* set DB ID from Lua client */
addReplyErrorFormat
(
c
,
"Error running script (call to %s): %s
\n
"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录