Skip to content

Commit

Permalink
fix some problem
Browse files Browse the repository at this point in the history
Change-Id: I5656dc8a4f8010966b3f508e9c72bc7c26395f21
Signed-off-by: wei.kukey <wei.kukey@gmail.com>
  • Loading branch information
kukey committed Jun 11, 2024
1 parent 456447f commit 3e0939c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 45 deletions.
9 changes: 3 additions & 6 deletions src/commands.def
Original file line number Diff line number Diff line change
Expand Up @@ -5219,10 +5219,7 @@ struct COMMAND_ARG SCRIPT_DEBUG_Args[] = {

#ifndef SKIP_CMD_TIPS_TABLE
/* SCRIPT DUMP tips */
const char *SCRIPT_DUMP_Tips[] = {
"request_policy:all_shards",
"response_policy:agg_logical_and",
};
#define SCRIPT_DUMP_Tips NULL
#endif

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

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

/********** SCRIPT EXISTS ********************/
Expand Down Expand Up @@ -5358,7 +5355,7 @@ struct COMMAND_ARG SCRIPT_LOAD_Args[] = {
/* 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 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},
{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)},
Expand Down
35 changes: 13 additions & 22 deletions src/commands/script-dump.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"DUMP": {
"summary": "Dump server-side Lua scripts in the script cache.",
"complexity": "O(N) with N being the number of scripts to check (so checking a single script is an O(1) operation).",
"summary": "Dump server-side Lua script in the script cache.",
"complexity": "O(1).",
"group": "scripting",
"since": "8.0.0",
"arity": -3,
Expand All @@ -13,32 +13,23 @@
"acl_categories": [
"SCRIPTING"
],
"command_tips": [
"REQUEST_POLICY:ALL_SHARDS",
"RESPONSE_POLICY:AGG_LOGICAL_AND"
],
"arguments": [
{
"name": "sha1",
"type": "string",
"multiple": true
"type": "string"
}
],
"reply_schema": {
"description": "An array of lua scripts that correspond to the specified SHA1 digest arguments.",
"type": "array",
"items": {
"oneOf": [
{
"description": "lua script if sha1 hash exists in script cache.",
"type": "string"
},
{
"description": "null if sha1 hash does not exist in script cache.",
"type": "null"
}
]
}
"oneOf": [
{
"description": "lua script if sha1 hash exists in script cache.",
"type": "string"
},
{
"description": "null if sha1 hash does not exist in script cache.",
"type": "null"
}
]
}
}
}
26 changes: 11 additions & 15 deletions src/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ void scriptCommand(client *c) {
" Kill the currently executing Lua script.",
"LOAD <script>",
" Load a script into the scripts cache without executing it.",
"DUMP <sha1> [<sha1> ...]",
"DUMP <sha1>",
" Dump a script from the scipts cache.",
NULL
};
Expand Down Expand Up @@ -731,24 +731,20 @@ NULL
addReplyError(c, "Use SCRIPT DEBUG YES/SYNC/NO");
return;
}
} else if (c->argc > 2 && !strcasecmp(c->argv[1]->ptr, "dump")) {
int j;
} else if (c->argc == 3 && !strcasecmp(c->argv[1]->ptr, "dump")) {
dictEntry *de;
luaScript *ls;

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

if ((de = dictFind(lctx.lua_scripts, c->argv[j]->ptr))) {
ls = dictGetVal(de);
addReplyBulk(c, ls->body);
} else {
addReply(c, shared.null[c->resp]);
}
if ((de = dictFind(lctx.lua_scripts, c->argv[2]->ptr))) {
ls = dictGetVal(de);
addReplyBulk(c, ls->body);
} else {
addReply(c, shared.null[c->resp]);
}
} else {
addReplySubcommandSyntaxError(c);
Expand Down
9 changes: 7 additions & 2 deletions tests/unit/scripting.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,13 @@ start_server {tags {"scripting"}} {

test {SCRIPT DUMP - is able to dump scripts from the scripting cache} {
list \
[r script dump b534286061d4b9e4026607613b95c06c06015ae8 b534286061d4b9 b534286061d4b9e4026607613b95c06c06015ae8 b534286061d4b9e4026607613b95c06c06015a11] \
} {{{return 'loaded'} {} {return 'loaded'} {}}}
[r script dump b534286061d4b9e4026607613b95c06c06015ae8] \
[r script dump b534286061d4b9e4026607613b95c06c06015ae1]
} {{return 'loaded'} {}}

test {SCRIPT DUMP - wrong sha1 length} {
assert_error "ERR Sha1 length must be 40" {r script dump b534286061d4b06c06015ae8}
}

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

0 comments on commit 3e0939c

Please sign in to comment.