Skip to content

Commit 3e0939c

Browse files
committed
fix some problem
Change-Id: I5656dc8a4f8010966b3f508e9c72bc7c26395f21 Signed-off-by: wei.kukey <[email protected]>
1 parent 456447f commit 3e0939c

4 files changed

Lines changed: 34 additions & 45 deletions

File tree

src/commands.def

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5219,10 +5219,7 @@ struct COMMAND_ARG SCRIPT_DEBUG_Args[] = {
52195219

52205220
#ifndef SKIP_CMD_TIPS_TABLE
52215221
/* SCRIPT DUMP tips */
5222-
const char *SCRIPT_DUMP_Tips[] = {
5223-
"request_policy:all_shards",
5224-
"response_policy:agg_logical_and",
5225-
};
5222+
#define SCRIPT_DUMP_Tips NULL
52265223
#endif
52275224

52285225
#ifndef SKIP_CMD_KEY_SPECS_TABLE
@@ -5232,7 +5229,7 @@ const char *SCRIPT_DUMP_Tips[] = {
52325229

52335230
/* SCRIPT DUMP argument table */
52345231
struct COMMAND_ARG SCRIPT_DUMP_Args[] = {
5235-
{MAKE_ARG("sha1",ARG_TYPE_STRING,-1,NULL,NULL,NULL,CMD_ARG_MULTIPLE,0,NULL)},
5232+
{MAKE_ARG("sha1",ARG_TYPE_STRING,-1,NULL,NULL,NULL,CMD_ARG_NONE,0,NULL)},
52365233
};
52375234

52385235
/********** SCRIPT EXISTS ********************/
@@ -5358,7 +5355,7 @@ struct COMMAND_ARG SCRIPT_LOAD_Args[] = {
53585355
/* SCRIPT command table */
53595356
struct COMMAND_STRUCT SCRIPT_Subcommands[] = {
53605357
{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},
5361-
{MAKE_CMD("dump","Dump server-side Lua scripts 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).","7.2.4",CMD_DOC_NONE,NULL,NULL,"scripting",COMMAND_GROUP_SCRIPTING,SCRIPT_DUMP_History,0,SCRIPT_DUMP_Tips,2,scriptCommand,-3,CMD_NOSCRIPT,ACL_CATEGORY_SCRIPTING,SCRIPT_DUMP_Keyspecs,0,NULL,1),.args=SCRIPT_DUMP_Args},
5358+
{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},
53625359
{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},
53635360
{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},
53645361
{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)},

src/commands/script-dump.json

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"DUMP": {
3-
"summary": "Dump server-side Lua scripts in the script cache.",
4-
"complexity": "O(N) with N being the number of scripts to check (so checking a single script is an O(1) operation).",
3+
"summary": "Dump server-side Lua script in the script cache.",
4+
"complexity": "O(1).",
55
"group": "scripting",
66
"since": "8.0.0",
77
"arity": -3,
@@ -13,32 +13,23 @@
1313
"acl_categories": [
1414
"SCRIPTING"
1515
],
16-
"command_tips": [
17-
"REQUEST_POLICY:ALL_SHARDS",
18-
"RESPONSE_POLICY:AGG_LOGICAL_AND"
19-
],
2016
"arguments": [
2117
{
2218
"name": "sha1",
23-
"type": "string",
24-
"multiple": true
19+
"type": "string"
2520
}
2621
],
2722
"reply_schema": {
28-
"description": "An array of lua scripts that correspond to the specified SHA1 digest arguments.",
29-
"type": "array",
30-
"items": {
31-
"oneOf": [
32-
{
33-
"description": "lua script if sha1 hash exists in script cache.",
34-
"type": "string"
35-
},
36-
{
37-
"description": "null if sha1 hash does not exist in script cache.",
38-
"type": "null"
39-
}
40-
]
41-
}
23+
"oneOf": [
24+
{
25+
"description": "lua script if sha1 hash exists in script cache.",
26+
"type": "string"
27+
},
28+
{
29+
"description": "null if sha1 hash does not exist in script cache.",
30+
"type": "null"
31+
}
32+
]
4233
}
4334
}
4435
}

src/eval.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ void scriptCommand(client *c) {
676676
" Kill the currently executing Lua script.",
677677
"LOAD <script>",
678678
" Load a script into the scripts cache without executing it.",
679-
"DUMP <sha1> [<sha1> ...]",
679+
"DUMP <sha1>",
680680
" Dump a script from the scipts cache.",
681681
NULL
682682
};
@@ -731,24 +731,20 @@ NULL
731731
addReplyError(c, "Use SCRIPT DEBUG YES/SYNC/NO");
732732
return;
733733
}
734-
} else if (c->argc > 2 && !strcasecmp(c->argv[1]->ptr, "dump")) {
735-
int j;
734+
} else if (c->argc == 3 && !strcasecmp(c->argv[1]->ptr, "dump")) {
736735
dictEntry *de;
737736
luaScript *ls;
738737

739-
addReplyArrayLen(c, c->argc - 2);
740-
for (j = 2; j < c->argc; j++) {
741-
if (sdslen(c->argv[j]->ptr) != 40) {
742-
addReply(c, shared.null[c->resp]);
743-
continue;
744-
}
738+
if (sdslen(c->argv[2]->ptr) != 40) {
739+
addReplyError(c, "Sha1 length must be 40");
740+
return;
741+
}
745742

746-
if ((de = dictFind(lctx.lua_scripts, c->argv[j]->ptr))) {
747-
ls = dictGetVal(de);
748-
addReplyBulk(c, ls->body);
749-
} else {
750-
addReply(c, shared.null[c->resp]);
751-
}
743+
if ((de = dictFind(lctx.lua_scripts, c->argv[2]->ptr))) {
744+
ls = dictGetVal(de);
745+
addReplyBulk(c, ls->body);
746+
} else {
747+
addReply(c, shared.null[c->resp]);
752748
}
753749
} else {
754750
addReplySubcommandSyntaxError(c);

tests/unit/scripting.tcl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,13 @@ start_server {tags {"scripting"}} {
640640

641641
test {SCRIPT DUMP - is able to dump scripts from the scripting cache} {
642642
list \
643-
[r script dump b534286061d4b9e4026607613b95c06c06015ae8 b534286061d4b9 b534286061d4b9e4026607613b95c06c06015ae8 b534286061d4b9e4026607613b95c06c06015a11] \
644-
} {{{return 'loaded'} {} {return 'loaded'} {}}}
643+
[r script dump b534286061d4b9e4026607613b95c06c06015ae8] \
644+
[r script dump b534286061d4b9e4026607613b95c06c06015ae1]
645+
} {{return 'loaded'} {}}
646+
647+
test {SCRIPT DUMP - wrong sha1 length} {
648+
assert_error "ERR Sha1 length must be 40" {r script dump b534286061d4b06c06015ae8}
649+
}
645650

646651
test "SORT is normally not alpha re-ordered for the scripting engine" {
647652
r del myset

0 commit comments

Comments
 (0)