Skip to content

Commit

Permalink
use script-show subcommand
Browse files Browse the repository at this point in the history
Change-Id: Ieb1b35629728b269c270ea97d775b4c2542a755f
Signed-off-by: wei.kukey <wei.kukey@gmail.com>
  • Loading branch information
kukey committed Jun 18, 2024
1 parent 24367ee commit ac7f7c0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 35 deletions.
46 changes: 23 additions & 23 deletions src/commands.def
Original file line number Diff line number Diff line change
Expand Up @@ -5210,28 +5210,6 @@ struct COMMAND_ARG SCRIPT_DEBUG_Args[] = {
{MAKE_ARG("mode",ARG_TYPE_ONEOF,-1,NULL,NULL,NULL,CMD_ARG_NONE,3,NULL),.subargs=SCRIPT_DEBUG_mode_Subargs},
};

/********** SCRIPT DUMP ********************/

#ifndef SKIP_CMD_HISTORY_TABLE
/* SCRIPT DUMP history */
#define SCRIPT_DUMP_History NULL
#endif

#ifndef SKIP_CMD_TIPS_TABLE
/* SCRIPT DUMP tips */
#define SCRIPT_DUMP_Tips NULL
#endif

#ifndef SKIP_CMD_KEY_SPECS_TABLE
/* SCRIPT DUMP key specs */
#define SCRIPT_DUMP_Keyspecs NULL
#endif

/* SCRIPT DUMP argument table */
struct COMMAND_ARG SCRIPT_DUMP_Args[] = {
{MAKE_ARG("sha1",ARG_TYPE_STRING,-1,NULL,NULL,NULL,CMD_ARG_NONE,0,NULL)},
};

/********** SCRIPT EXISTS ********************/

#ifndef SKIP_CMD_HISTORY_TABLE
Expand Down Expand Up @@ -5352,15 +5330,37 @@ struct COMMAND_ARG SCRIPT_LOAD_Args[] = {
{MAKE_ARG("script",ARG_TYPE_STRING,-1,NULL,NULL,NULL,CMD_ARG_NONE,0,NULL)},
};

/********** SCRIPT SHOW ********************/

#ifndef SKIP_CMD_HISTORY_TABLE
/* SCRIPT SHOW history */
#define SCRIPT_SHOW_History NULL
#endif

#ifndef SKIP_CMD_TIPS_TABLE
/* SCRIPT SHOW tips */
#define SCRIPT_SHOW_Tips NULL
#endif

#ifndef SKIP_CMD_KEY_SPECS_TABLE
/* SCRIPT SHOW key specs */
#define SCRIPT_SHOW_Keyspecs NULL
#endif

/* SCRIPT SHOW argument table */
struct COMMAND_ARG SCRIPT_SHOW_Args[] = {
{MAKE_ARG("sha1",ARG_TYPE_STRING,-1,NULL,NULL,NULL,CMD_ARG_NONE,0,NULL)},
};

/* SCRIPT command table */
struct COMMAND_STRUCT SCRIPT_Subcommands[] = {
{MAKE_CMD("debug","Sets the debug mode of server-side Lua scripts.","O(1)","3.2.0",CMD_DOC_NONE,NULL,NULL,"scripting",COMMAND_GROUP_SCRIPTING,SCRIPT_DEBUG_History,0,SCRIPT_DEBUG_Tips,0,scriptCommand,3,CMD_NOSCRIPT,ACL_CATEGORY_SCRIPTING,SCRIPT_DEBUG_Keyspecs,0,NULL,1),.args=SCRIPT_DEBUG_Args},
{MAKE_CMD("dump","Dump server-side Lua script in the script cache.","O(1).","8.0.0",CMD_DOC_NONE,NULL,NULL,"scripting",COMMAND_GROUP_SCRIPTING,SCRIPT_DUMP_History,0,SCRIPT_DUMP_Tips,0,scriptCommand,3,CMD_NOSCRIPT,ACL_CATEGORY_SCRIPTING,SCRIPT_DUMP_Keyspecs,0,NULL,1),.args=SCRIPT_DUMP_Args},
{MAKE_CMD("exists","Determines whether server-side Lua scripts exist in the script cache.","O(N) with N being the number of scripts to check (so checking a single script is an O(1) operation).","2.6.0",CMD_DOC_NONE,NULL,NULL,"scripting",COMMAND_GROUP_SCRIPTING,SCRIPT_EXISTS_History,0,SCRIPT_EXISTS_Tips,2,scriptCommand,-3,CMD_NOSCRIPT,ACL_CATEGORY_SCRIPTING,SCRIPT_EXISTS_Keyspecs,0,NULL,1),.args=SCRIPT_EXISTS_Args},
{MAKE_CMD("flush","Removes all server-side Lua scripts from the script cache.","O(N) with N being the number of scripts in cache","2.6.0",CMD_DOC_NONE,NULL,NULL,"scripting",COMMAND_GROUP_SCRIPTING,SCRIPT_FLUSH_History,1,SCRIPT_FLUSH_Tips,2,scriptCommand,-2,CMD_NOSCRIPT,ACL_CATEGORY_SCRIPTING,SCRIPT_FLUSH_Keyspecs,0,NULL,1),.args=SCRIPT_FLUSH_Args},
{MAKE_CMD("help","Returns helpful text about the different subcommands.","O(1)","5.0.0",CMD_DOC_NONE,NULL,NULL,"scripting",COMMAND_GROUP_SCRIPTING,SCRIPT_HELP_History,0,SCRIPT_HELP_Tips,0,scriptCommand,2,CMD_LOADING|CMD_STALE,ACL_CATEGORY_SCRIPTING,SCRIPT_HELP_Keyspecs,0,NULL,0)},
{MAKE_CMD("kill","Terminates a server-side Lua script during execution.","O(1)","2.6.0",CMD_DOC_NONE,NULL,NULL,"scripting",COMMAND_GROUP_SCRIPTING,SCRIPT_KILL_History,0,SCRIPT_KILL_Tips,2,scriptCommand,2,CMD_NOSCRIPT|CMD_ALLOW_BUSY,ACL_CATEGORY_SCRIPTING,SCRIPT_KILL_Keyspecs,0,NULL,0)},
{MAKE_CMD("load","Loads a server-side Lua script to the script cache.","O(N) with N being the length in bytes of the script body.","2.6.0",CMD_DOC_NONE,NULL,NULL,"scripting",COMMAND_GROUP_SCRIPTING,SCRIPT_LOAD_History,0,SCRIPT_LOAD_Tips,2,scriptCommand,3,CMD_NOSCRIPT|CMD_STALE,ACL_CATEGORY_SCRIPTING,SCRIPT_LOAD_Keyspecs,0,NULL,1),.args=SCRIPT_LOAD_Args},
{MAKE_CMD("show","Show server-side lua script in the script cache.","O(1).","8.0.0",CMD_DOC_NONE,NULL,NULL,"scripting",COMMAND_GROUP_SCRIPTING,SCRIPT_SHOW_History,0,SCRIPT_SHOW_Tips,0,scriptCommand,3,CMD_NOSCRIPT,ACL_CATEGORY_SCRIPTING,SCRIPT_SHOW_Keyspecs,0,NULL,1),.args=SCRIPT_SHOW_Args},
{0}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"DUMP": {
"summary": "Dump server-side Lua script in the script cache.",
"SHOW": {
"summary": "Show server-side lua script in the script cache.",
"complexity": "O(1).",
"group": "scripting",
"since": "8.0.0",
Expand Down
6 changes: 3 additions & 3 deletions src/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,8 +675,8 @@ void scriptCommand(client *c) {
" Kill the currently executing Lua script.",
"LOAD <script>",
" Load a script into the scripts cache without executing it.",
"DUMP <sha1>",
" Dump a script from the scripts cache.",
"SHOW <sha1>",
" Show a script from the scripts cache.",
NULL
};
/* clang-format on */
Expand Down Expand Up @@ -730,7 +730,7 @@ NULL
addReplyError(c, "Use SCRIPT DEBUG YES/SYNC/NO");
return;
}
} else if (c->argc == 3 && !strcasecmp(c->argv[1]->ptr, "dump")) {
} else if (c->argc == 3 && !strcasecmp(c->argv[1]->ptr, "show")) {
dictEntry *de;
luaScript *ls;

Expand Down
14 changes: 7 additions & 7 deletions tests/unit/scripting.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -638,19 +638,19 @@ start_server {tags {"scripting"}} {
[r evalsha b534286061d4b9e4026607613b95c06c06015ae8 0]
} {b534286061d4b9e4026607613b95c06c06015ae8 loaded}

test {SCRIPT DUMP - is able to dump scripts from the scripting cache} {
test {SCRIPT SHOW - is able to dump scripts from the scripting cache} {
r script load "return 'dump'"
r script dump 4f5a49d7b18244a3b100d159b78b51474e23e081
r script show 4f5a49d7b18244a3b100d159b78b51474e23e081
} {return 'dump'}

test {SCRIPT DUMP - wrong sha1 length or invalid sha1 char return noscript error} {
assert_error {NOSCRIPT*} {r script dump b534286061d4b06c06015ae8}
assert_error {NOSCRIPT*} {r script dump AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA}
test {SCRIPT SHOW - wrong sha1 length or invalid sha1 char return noscript error} {
assert_error {NOSCRIPT*} {r script show b534286061d4b06c06015ae8}
assert_error {NOSCRIPT*} {r script show AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA}
}

test {SCRIPT DUMP - script not exist return noscript error} {
test {SCRIPT SHOW - script not exist return noscript error} {
r script flush
assert_error {NOSCRIPT*} {r script dump 4f5a49d7b18244a3b100d159b78b51474e23e081}
assert_error {NOSCRIPT*} {r script show 4f5a49d7b18244a3b100d159b78b51474e23e081}
}

test "SORT is normally not alpha re-ordered for the scripting engine" {
Expand Down

0 comments on commit ac7f7c0

Please sign in to comment.