Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
d6c24ff6
Commit
d6c24ff6
authored
Nov 05, 2015
by
antirez
Browse files
Initialize all Lua scripting related things into scripting.c
parent
1fb2b91a
Changes
3
Show whitespace changes
Inline
Side-by-side
src/scripting.c
View file @
d6c24ff6
...
...
@@ -790,12 +790,26 @@ void scriptingEnableGlobalsProtection(lua_State *lua) {
}
/* 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
)
{
*
* This function is called the first time at server startup with
* the 'setup' argument set to 1.
*
* It can be called again multiple times during the lifetime of the Redis
* process, with 'setup' set to 0, and following a scriptingRelease() call,
* in order to reset the Lua scripting environment.
*
* However it is simpler to just call scriptingReset() that does just that. */
void
scriptingInit
(
int
setup
)
{
lua_State
*
lua
=
lua_open
();
if
(
setup
)
{
server
.
lua_client
=
NULL
;
server
.
lua_caller
=
NULL
;
server
.
lua_timedout
=
0
;
server
.
lua_always_replicate_commands
=
0
;
/* Only DEBUG can change it.*/
server
.
lua_time_limit
=
LUA_SCRIPT_TIME_LIMIT
;
}
luaLoadLibraries
(
lua
);
luaRemoveUnsupportedFunctions
(
lua
);
...
...
@@ -952,7 +966,7 @@ void scriptingRelease(void) {
void
scriptingReset
(
void
)
{
scriptingRelease
();
scriptingInit
();
scriptingInit
(
0
);
}
/* Set an array of Redis String Objects as a Lua array (table) stored into a
...
...
@@ -1011,6 +1025,15 @@ int redis_math_randomseed (lua_State *L) {
return
0
;
}
/* ---------------------------------------------------------------------------
* LDB: Redis Lua debugging facilities
* ------------------------------------------------------------------------- */
/* Enable debug mode of Lua scripts for this client. */
void
ldbEnable
(
client
*
c
)
{
c
->
flags
|=
CLIENT_LUA_DEBUG
;
}
/* ---------------------------------------------------------------------------
* EVAL and SCRIPT commands implementation
* ------------------------------------------------------------------------- */
...
...
@@ -1331,6 +1354,9 @@ void scriptCommand(client *c) {
server
.
lua_kill
=
1
;
addReply
(
c
,
shared
.
ok
);
}
}
else
if
(
c
->
argc
==
2
&&
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"debug"
))
{
ldbEnable
(
c
);
addReply
(
c
,
shared
.
ok
);
}
else
{
addReplyError
(
c
,
"Unknown SCRIPT subcommand or wrong # of args."
);
}
...
...
src/server.c
View file @
d6c24ff6
...
...
@@ -1495,11 +1495,6 @@ void initServerConfig(void) {
server
.
cluster_slave_validity_factor
=
CLUSTER_DEFAULT_SLAVE_VALIDITY
;
server
.
cluster_require_full_coverage
=
CLUSTER_DEFAULT_REQUIRE_FULL_COVERAGE
;
server
.
cluster_configfile
=
zstrdup
(
CONFIG_DEFAULT_CLUSTER_CONFIG_FILE
);
server
.
lua_caller
=
NULL
;
server
.
lua_time_limit
=
LUA_SCRIPT_TIME_LIMIT
;
server
.
lua_client
=
NULL
;
server
.
lua_timedout
=
0
;
server
.
lua_always_replicate_commands
=
0
;
/* Only DEBUG can change it. */
server
.
migrate_cached_sockets
=
dictCreate
(
&
migrateCacheDictType
,
NULL
);
server
.
next_client_id
=
1
;
/* Client IDs, start from 1 .*/
server
.
loading_process_events_interval_bytes
=
(
1024
*
1024
*
2
);
...
...
@@ -1951,7 +1946,7 @@ void initServer(void) {
if
(
server
.
cluster_enabled
)
clusterInit
();
replicationScriptCacheInit
();
scriptingInit
();
scriptingInit
(
1
);
slowlogInit
();
latencyMonitorInit
();
bioInit
();
...
...
src/server.h
View file @
d6c24ff6
...
...
@@ -1441,7 +1441,7 @@ int redis_check_rdb(char *rdbfilename);
int
redis_check_rdb_main
(
char
**
argv
,
int
argc
);
/* Scripting */
void
scriptingInit
(
void
);
void
scriptingInit
(
int
setup
);
/* Blocked clients */
void
processUnblockedClients
(
void
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment