MCPcopy Create free account
hub / github.com/apache/kvrocks / Execute

Method Execute

src/commands/cmd_function.cc:32–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30
31struct CommandFunction : Commander {
32 Status Execute(engine::Context &ctx, Server *srv, Connection *conn, std::string *output) override {
33 CommandParser parser(args_, 1);
34
35 if (parser.EatEqICase("load")) {
36 bool replace = false;
37 if (parser.EatEqICase("replace")) {
38 replace = true;
39 }
40
41 std::string libname;
42 auto s = lua::FunctionLoad(conn, &ctx, GET_OR_RET(parser.TakeStr()), true, replace, &libname);
43 if (!s) return s;
44
45 *output = SimpleString(libname);
46 return Status::OK();
47 } else if (parser.EatEqICase("list")) {
48 std::string libname;
49 if (parser.EatEqICase("libraryname")) {
50 libname = GET_OR_RET(parser.TakeStr());
51 }
52
53 bool with_code = false;
54 if (parser.EatEqICase("withcode")) {
55 with_code = true;
56 }
57
58 return lua::FunctionList(srv, conn, ctx, libname, with_code, output);
59 } else if (parser.EatEqICase("listfunc")) {
60 std::string funcname;
61 if (parser.EatEqICase("funcname")) {
62 funcname = GET_OR_RET(parser.TakeStr());
63 }
64
65 return lua::FunctionListFunc(srv, conn, ctx, funcname, output);
66 } else if (parser.EatEqICase("listlib")) {
67 auto libname = GET_OR_RET(parser.TakeStr().Prefixed("expect a library name"));
68
69 return lua::FunctionListLib(conn, libname, output);
70 } else if (parser.EatEqICase("delete")) {
71 auto libname = GET_OR_RET(parser.TakeStr());
72 if (!lua::FunctionIsLibExist(conn, &ctx, libname)) {
73 return {Status::NotOK, "no such library"};
74 }
75 auto s = lua::FunctionDelete(ctx, conn, libname);
76 if (!s) return s;
77 s = srv->Propagate(engine::kPropagateScriptCommand, args_);
78 if (!s) return s;
79
80 *output = RESP_OK;
81 return Status::OK();
82 } else if (parser.EatEqICase("flush")) {
83 auto s = lua::FunctionFlush(conn, &ctx);
84 if (!s) return s;
85 s = srv->Propagate(engine::kPropagateScriptCommand, args_);
86 if (!s) return s;
87
88 *output = RESP_OK;
89 return Status::OK();

Callers

nothing calls this directly

Calls 12

FunctionLoadFunction · 0.85
SimpleStringFunction · 0.85
FunctionListFunction · 0.85
FunctionListFuncFunction · 0.85
FunctionListLibFunction · 0.85
FunctionIsLibExistFunction · 0.85
FunctionDeleteFunction · 0.85
FunctionFlushFunction · 0.85
EatEqICaseMethod · 0.80
TakeStrMethod · 0.80
PropagateMethod · 0.80
PrefixedMethod · 0.45

Tested by

no test coverage detected