diff --git a/src/cluster_legacy.c b/src/cluster_legacy.c index 90f31e3cd5..685bafcbe4 100644 --- a/src/cluster_legacy.c +++ b/src/cluster_legacy.c @@ -561,7 +561,7 @@ int clusterLoadConfig(char *filename) { clusterAddNode(master); } /* shard_id can be absent if we are loading a nodes.conf generated - * by an older version of Redis; we should follow the primary's + * by an older version; we should follow the primary's * shard_id in this case */ if (auxFieldHandlers[af_shard_id].isPresent(n) == 0) { memcpy(n->shard_id, master->shard_id, CLUSTER_NAMELEN); diff --git a/src/debug.c b/src/debug.c index 51e9c6e9f6..fc2a49cca8 100644 --- a/src/debug.c +++ b/src/debug.c @@ -925,7 +925,7 @@ void debugCommand(client *c) { addReply(c, shared.ok); } else if (!strcasecmp(c->argv[1]->ptr, "stringmatch-test") && c->argc == 2) { stringmatchlen_fuzz_test(); - addReplyStatus(c, "Apparently Redis did not crash: test passed"); + addReplyStatus(c, "Apparently the server did not crash: test passed"); } else if (!strcasecmp(c->argv[1]->ptr, "set-disable-deny-scripts") && c->argc == 3) { server.script_disable_deny_script = atoi(c->argv[2]->ptr); addReply(c, shared.ok); diff --git a/src/eval.c b/src/eval.c index e50acd179c..464c8ef487 100644 --- a/src/eval.c +++ b/src/eval.c @@ -99,7 +99,7 @@ struct ldbState { int bp[LDB_BREAKPOINTS_MAX]; /* An array of breakpoints line numbers. */ int bpcount; /* Number of valid entries inside bp. */ int step; /* Stop at next line regardless of breakpoints. */ - int luabp; /* Stop at next line because redis.breakpoint() was called. */ + int luabp; /* Stop at next line because server.breakpoint() was called. */ sds *src; /* Lua script source code split by line. */ int lines; /* Number of lines in 'src'. */ int currentline; /* Current line number. */ @@ -114,7 +114,7 @@ struct ldbState { /* Perform the SHA1 of the input string. We use this both for hashing script * bodies in order to obtain the Lua function name, and in the implementation - * of redis.sha1(). + * of server.sha1(). * * 'digest' should point to a 41 bytes buffer: 40 for SHA1 converted into an * hexadecimal number, plus 1 byte for null term. */ @@ -135,12 +135,12 @@ void sha1hex(char *digest, char *script, size_t len) { digest[40] = '\0'; } -/* redis.breakpoint() +/* server.breakpoint() * * Allows to stop execution during a debugging session from within * the Lua code implementation, like if a breakpoint was set in the code * immediately after the function. */ -int luaRedisBreakpointCommand(lua_State *lua) { +int luaServerBreakpointCommand(lua_State *lua) { if (ldb.active) { ldb.luabp = 1; lua_pushboolean(lua, 1); @@ -150,12 +150,12 @@ int luaRedisBreakpointCommand(lua_State *lua) { return 1; } -/* redis.debug() +/* server.debug() * * Log a string message into the output console. * Can take multiple arguments that will be separated by commas. * Nothing is returned to the caller. */ -int luaRedisDebugCommand(lua_State *lua) { +int luaServerDebugCommand(lua_State *lua) { if (!ldb.active) return 0; int argc = lua_gettop(lua); sds log = sdscatprintf(sdsempty(), " line %d: ", ldb.currentline); @@ -167,14 +167,14 @@ int luaRedisDebugCommand(lua_State *lua) { return 0; } -/* redis.replicate_commands() +/* server.replicate_commands() * * DEPRECATED: Now do nothing and always return true. * Turn on single commands replication if the script never called * a write command so far, and returns true. Otherwise if the script * already started to write, returns false and stick to whole scripts * replication, which is our default. */ -int luaRedisReplicateCommandsCommand(lua_State *lua) { +int luaServerReplicateCommandsCommand(lua_State *lua) { lua_pushboolean(lua, 1); return 1; } @@ -205,27 +205,27 @@ void scriptingInit(int setup) { lctx.lua_scripts_lru_list = listCreate(); lctx.lua_scripts_mem = 0; - luaRegisterRedisAPI(lua); + luaRegisterServerAPI(lua); /* register debug commands */ - lua_getglobal(lua, "redis"); + lua_getglobal(lua, "server"); - /* redis.breakpoint */ + /* server.breakpoint */ lua_pushstring(lua, "breakpoint"); - lua_pushcfunction(lua, luaRedisBreakpointCommand); + lua_pushcfunction(lua, luaServerBreakpointCommand); lua_settable(lua, -3); - /* redis.debug */ + /* server.debug */ lua_pushstring(lua, "debug"); - lua_pushcfunction(lua, luaRedisDebugCommand); + lua_pushcfunction(lua, luaServerDebugCommand); lua_settable(lua, -3); - /* redis.replicate_commands */ + /* server.replicate_commands */ lua_pushstring(lua, "replicate_commands"); - lua_pushcfunction(lua, luaRedisReplicateCommandsCommand); + lua_pushcfunction(lua, luaServerReplicateCommandsCommand); lua_settable(lua, -3); - lua_setglobal(lua, "redis"); + lua_setglobal(lua, "server"); /* Add a helper function we use for pcall error reporting. * Note that when the error is in the C function we want to report the @@ -1204,50 +1204,50 @@ void ldbLogStackValue(lua_State *lua, char *prefix) { ldbLogWithMaxLen(s); } -char *ldbRedisProtocolToHuman_Int(sds *o, char *reply); -char *ldbRedisProtocolToHuman_Bulk(sds *o, char *reply); -char *ldbRedisProtocolToHuman_Status(sds *o, char *reply); -char *ldbRedisProtocolToHuman_MultiBulk(sds *o, char *reply); -char *ldbRedisProtocolToHuman_Set(sds *o, char *reply); -char *ldbRedisProtocolToHuman_Map(sds *o, char *reply); -char *ldbRedisProtocolToHuman_Null(sds *o, char *reply); -char *ldbRedisProtocolToHuman_Bool(sds *o, char *reply); -char *ldbRedisProtocolToHuman_Double(sds *o, char *reply); +char *ldbRespToHuman_Int(sds *o, char *reply); +char *ldbRespToHuman_Bulk(sds *o, char *reply); +char *ldbRespToHuman_Status(sds *o, char *reply); +char *ldbRespToHuman_MultiBulk(sds *o, char *reply); +char *ldbRespToHuman_Set(sds *o, char *reply); +char *ldbRespToHuman_Map(sds *o, char *reply); +char *ldbRespToHuman_Null(sds *o, char *reply); +char *ldbRespToHuman_Bool(sds *o, char *reply); +char *ldbRespToHuman_Double(sds *o, char *reply); /* Get RESP from 'reply' and appends it in human readable form to * the passed SDS string 'o'. * * Note that the SDS string is passed by reference (pointer of pointer to * char*) so that we can return a modified pointer, as for SDS semantics. */ -char *ldbRedisProtocolToHuman(sds *o, char *reply) { +char *ldbRespToHuman(sds *o, char *reply) { char *p = reply; /* clang-format off */ switch(*p) { - case ':': p = ldbRedisProtocolToHuman_Int(o,reply); break; - case '$': p = ldbRedisProtocolToHuman_Bulk(o,reply); break; - case '+': p = ldbRedisProtocolToHuman_Status(o,reply); break; - case '-': p = ldbRedisProtocolToHuman_Status(o,reply); break; - case '*': p = ldbRedisProtocolToHuman_MultiBulk(o,reply); break; - case '~': p = ldbRedisProtocolToHuman_Set(o,reply); break; - case '%': p = ldbRedisProtocolToHuman_Map(o,reply); break; - case '_': p = ldbRedisProtocolToHuman_Null(o,reply); break; - case '#': p = ldbRedisProtocolToHuman_Bool(o,reply); break; - case ',': p = ldbRedisProtocolToHuman_Double(o,reply); break; + case ':': p = ldbRespToHuman_Int(o,reply); break; + case '$': p = ldbRespToHuman_Bulk(o,reply); break; + case '+': p = ldbRespToHuman_Status(o,reply); break; + case '-': p = ldbRespToHuman_Status(o,reply); break; + case '*': p = ldbRespToHuman_MultiBulk(o,reply); break; + case '~': p = ldbRespToHuman_Set(o,reply); break; + case '%': p = ldbRespToHuman_Map(o,reply); break; + case '_': p = ldbRespToHuman_Null(o,reply); break; + case '#': p = ldbRespToHuman_Bool(o,reply); break; + case ',': p = ldbRespToHuman_Double(o,reply); break; } /* clang-format on */ return p; } -/* The following functions are helpers for ldbRedisProtocolToHuman(), each +/* The following functions are helpers for ldbRespToHuman(), each * take care of a given RESP return type. */ -char *ldbRedisProtocolToHuman_Int(sds *o, char *reply) { +char *ldbRespToHuman_Int(sds *o, char *reply) { char *p = strchr(reply + 1, '\r'); *o = sdscatlen(*o, reply + 1, p - reply - 1); return p + 2; } -char *ldbRedisProtocolToHuman_Bulk(sds *o, char *reply) { +char *ldbRespToHuman_Bulk(sds *o, char *reply) { char *p = strchr(reply + 1, '\r'); long long bulklen; @@ -1261,14 +1261,14 @@ char *ldbRedisProtocolToHuman_Bulk(sds *o, char *reply) { } } -char *ldbRedisProtocolToHuman_Status(sds *o, char *reply) { +char *ldbRespToHuman_Status(sds *o, char *reply) { char *p = strchr(reply + 1, '\r'); *o = sdscatrepr(*o, reply, p - reply); return p + 2; } -char *ldbRedisProtocolToHuman_MultiBulk(sds *o, char *reply) { +char *ldbRespToHuman_MultiBulk(sds *o, char *reply) { char *p = strchr(reply + 1, '\r'); long long mbulklen; int j = 0; @@ -1281,14 +1281,14 @@ char *ldbRedisProtocolToHuman_MultiBulk(sds *o, char *reply) { } *o = sdscatlen(*o, "[", 1); for (j = 0; j < mbulklen; j++) { - p = ldbRedisProtocolToHuman(o, p); + p = ldbRespToHuman(o, p); if (j != mbulklen - 1) *o = sdscatlen(*o, ",", 1); } *o = sdscatlen(*o, "]", 1); return p; } -char *ldbRedisProtocolToHuman_Set(sds *o, char *reply) { +char *ldbRespToHuman_Set(sds *o, char *reply) { char *p = strchr(reply + 1, '\r'); long long mbulklen; int j = 0; @@ -1297,14 +1297,14 @@ char *ldbRedisProtocolToHuman_Set(sds *o, char *reply) { p += 2; *o = sdscatlen(*o, "~(", 2); for (j = 0; j < mbulklen; j++) { - p = ldbRedisProtocolToHuman(o, p); + p = ldbRespToHuman(o, p); if (j != mbulklen - 1) *o = sdscatlen(*o, ",", 1); } *o = sdscatlen(*o, ")", 1); return p; } -char *ldbRedisProtocolToHuman_Map(sds *o, char *reply) { +char *ldbRespToHuman_Map(sds *o, char *reply) { char *p = strchr(reply + 1, '\r'); long long mbulklen; int j = 0; @@ -1313,22 +1313,22 @@ char *ldbRedisProtocolToHuman_Map(sds *o, char *reply) { p += 2; *o = sdscatlen(*o, "{", 1); for (j = 0; j < mbulklen; j++) { - p = ldbRedisProtocolToHuman(o, p); + p = ldbRespToHuman(o, p); *o = sdscatlen(*o, " => ", 4); - p = ldbRedisProtocolToHuman(o, p); + p = ldbRespToHuman(o, p); if (j != mbulklen - 1) *o = sdscatlen(*o, ",", 1); } *o = sdscatlen(*o, "}", 1); return p; } -char *ldbRedisProtocolToHuman_Null(sds *o, char *reply) { +char *ldbRespToHuman_Null(sds *o, char *reply) { char *p = strchr(reply + 1, '\r'); *o = sdscatlen(*o, "(null)", 6); return p + 2; } -char *ldbRedisProtocolToHuman_Bool(sds *o, char *reply) { +char *ldbRespToHuman_Bool(sds *o, char *reply) { char *p = strchr(reply + 1, '\r'); if (reply[1] == 't') *o = sdscatlen(*o, "#true", 5); @@ -1337,7 +1337,7 @@ char *ldbRedisProtocolToHuman_Bool(sds *o, char *reply) { return p + 2; } -char *ldbRedisProtocolToHuman_Double(sds *o, char *reply) { +char *ldbRespToHuman_Double(sds *o, char *reply) { char *p = strchr(reply + 1, '\r'); *o = sdscatlen(*o, "(double) ", 9); *o = sdscatlen(*o, reply + 1, p - reply - 1); @@ -1347,9 +1347,9 @@ char *ldbRedisProtocolToHuman_Double(sds *o, char *reply) { /* Log a RESP reply as debugger output, in a human readable format. * If the resulting string is longer than 'len' plus a few more chars * used as prefix, it gets truncated. */ -void ldbLogRedisReply(char *reply) { +void ldbLogRespReply(char *reply) { sds log = sdsnew(" "); - ldbRedisProtocolToHuman(&log, reply); + ldbRespToHuman(&log, reply); ldbLogWithMaxLen(log); } @@ -1487,10 +1487,10 @@ void ldbEval(lua_State *lua, sds *argv, int argc) { } /* Implement the debugger "server" command. We use a trick in order to make - * the implementation very simple: we just call the Lua redis.call() command + * the implementation very simple: we just call the Lua server.call() command * implementation, with ldb.step enabled, so as a side effect the command * and its reply are logged. */ -void ldbRedis(lua_State *lua, sds *argv, int argc) { +void ldbServer(lua_State *lua, sds *argv, int argc) { int j; if (!lua_checkstack(lua, argc + 1)) { @@ -1500,7 +1500,7 @@ void ldbRedis(lua_State *lua, sds *argv, int argc) { * given by the user (without the first argument) and we also push the 'server' global table and * 'server.call' function so: * (1 (server table)) + (1 (server.call function)) + (argc - 1 (all arguments without the first)) = argc + 1*/ - ldbLogRedisReply("max lua stack reached"); + ldbLogRespReply("max lua stack reached"); return; } @@ -1592,7 +1592,7 @@ int ldbRepl(lua_State *lua) { /* Execute the command. */ if (!strcasecmp(argv[0], "h") || !strcasecmp(argv[0], "help")) { - ldbLog(sdsnew("Redis Lua debugger help:")); + ldbLog(sdsnew("Lua debugger help:")); ldbLog(sdsnew("[h]elp Show this help.")); ldbLog(sdsnew("[s]tep Run current line and stop again.")); ldbLog(sdsnew("[n]ext Alias for step.")); @@ -1650,7 +1650,7 @@ int ldbRepl(lua_State *lua) { /* [r]redis or [v]alkey calls a command. We accept "server" too, but * not "s" because that's "step". Neither can we use [c]all because * "c" is continue. */ - ldbRedis(lua, argv, argc); + ldbServer(lua, argv, argc); ldbSendLogs(); } else if ((!strcasecmp(argv[0], "p") || !strcasecmp(argv[0], "print"))) { if (argc == 2) diff --git a/src/function_lua.c b/src/function_lua.c index 54453a8f35..685485e37e 100644 --- a/src/function_lua.c +++ b/src/function_lua.c @@ -274,7 +274,7 @@ static int luaRegisterFunctionReadNamedArgs(lua_State *lua, registerFunctionArgs luaFunctionCtx *lua_f_ctx = NULL; uint64_t flags = 0; if (!lua_istable(lua, 1)) { - err = "calling redis.register_function with a single argument is only applicable to Lua table (representing " + err = "calling server.register_function with a single argument is only applicable to Lua table (representing " "named arguments)."; goto error; } @@ -284,23 +284,23 @@ static int luaRegisterFunctionReadNamedArgs(lua_State *lua, registerFunctionArgs while (lua_next(lua, -2)) { /* Stack now: table, key, value */ if (!lua_isstring(lua, -2)) { - err = "named argument key given to redis.register_function is not a string"; + err = "named argument key given to server.register_function is not a string"; goto error; } const char *key = lua_tostring(lua, -2); if (!strcasecmp(key, "function_name")) { if (!(name = luaGetStringSds(lua, -1))) { - err = "function_name argument given to redis.register_function must be a string"; + err = "function_name argument given to server.register_function must be a string"; goto error; } } else if (!strcasecmp(key, "description")) { if (!(desc = luaGetStringSds(lua, -1))) { - err = "description argument given to redis.register_function must be a string"; + err = "description argument given to server.register_function must be a string"; goto error; } } else if (!strcasecmp(key, "callback")) { if (!lua_isfunction(lua, -1)) { - err = "callback argument given to redis.register_function must be a function"; + err = "callback argument given to server.register_function must be a function"; goto error; } int lua_function_ref = luaL_ref(lua, LUA_REGISTRYINDEX); @@ -310,7 +310,7 @@ static int luaRegisterFunctionReadNamedArgs(lua_State *lua, registerFunctionArgs continue; /* value was already popped, so no need to pop it out. */ } else if (!strcasecmp(key, "flags")) { if (!lua_istable(lua, -1)) { - err = "flags argument to redis.register_function must be a table representing function flags"; + err = "flags argument to server.register_function must be a table representing function flags"; goto error; } if (luaRegisterFunctionReadFlags(lua, &flags) != C_OK) { @@ -319,19 +319,19 @@ static int luaRegisterFunctionReadNamedArgs(lua_State *lua, registerFunctionArgs } } else { /* unknown argument was given, raise an error */ - err = "unknown argument given to redis.register_function"; + err = "unknown argument given to server.register_function"; goto error; } lua_pop(lua, 1); /* pop the value to continue the iteration */ } if (!name) { - err = "redis.register_function must get a function name argument"; + err = "server.register_function must get a function name argument"; goto error; } if (!lua_f_ctx) { - err = "redis.register_function must get a callback argument"; + err = "server.register_function must get a callback argument"; goto error; } @@ -355,12 +355,12 @@ static int luaRegisterFunctionReadPositionalArgs(lua_State *lua, registerFunctio sds name = NULL; luaFunctionCtx *lua_f_ctx = NULL; if (!(name = luaGetStringSds(lua, 1))) { - err = "first argument to redis.register_function must be a string"; + err = "first argument to server.register_function must be a string"; goto error; } if (!lua_isfunction(lua, 2)) { - err = "second argument to redis.register_function must be a function"; + err = "second argument to server.register_function must be a function"; goto error; } @@ -382,7 +382,7 @@ static int luaRegisterFunctionReadPositionalArgs(lua_State *lua, registerFunctio static int luaRegisterFunctionReadArgs(lua_State *lua, registerFunctionArgs *register_f_args) { int argc = lua_gettop(lua); if (argc < 1 || argc > 2) { - luaPushError(lua, "wrong number of arguments to redis.register_function"); + luaPushError(lua, "wrong number of arguments to server.register_function"); return C_ERR; } @@ -398,7 +398,7 @@ static int luaRegisterFunction(lua_State *lua) { loadCtx *load_ctx = luaGetFromRegistry(lua, REGISTRY_LOAD_CTX_NAME); if (!load_ctx) { - luaPushError(lua, "redis.register_function can only be called on FUNCTION LOAD command"); + luaPushError(lua, "server.register_function can only be called on FUNCTION LOAD command"); return luaError(lua); } @@ -423,7 +423,7 @@ int luaEngineInitEngine(void) { luaEngineCtx *lua_engine_ctx = zmalloc(sizeof(*lua_engine_ctx)); lua_engine_ctx->lua = lua_open(); - luaRegisterRedisAPI(lua_engine_ctx->lua); + luaRegisterServerAPI(lua_engine_ctx->lua); /* Register the library commands table and fields and store it to registry */ lua_newtable(lua_engine_ctx->lua); /* load library globals */ diff --git a/src/networking.c b/src/networking.c index 9274f21c05..cfe98a2c0e 100644 --- a/src/networking.c +++ b/src/networking.c @@ -1291,19 +1291,19 @@ void clientAcceptHandler(connection *conn) { * user what to do to fix it if needed. */ if (server.protected_mode && DefaultUser->flags & USER_FLAG_NOPASS) { if (connIsLocal(conn) != 1) { - char *err = "-DENIED Redis is running in protected mode because protected " + char *err = "-DENIED Running in protected mode because protected " "mode is enabled and no password is set for the default user. " "In this mode connections are only accepted from the loopback interface. " - "If you want to connect from external computers to Redis you " + "If you want to connect from external computers, you " "may adopt one of the following solutions: " "1) Just disable protected mode sending the command " "'CONFIG SET protected-mode no' from the loopback interface " - "by connecting to Redis from the same host the server is " - "running, however MAKE SURE Redis is not publicly accessible " + "by connecting from the same host the server is " + "running, however MAKE SURE it's not publicly accessible " "from internet if you do so. Use CONFIG REWRITE to make this " "change permanent. " "2) Alternatively you can just disable the protected mode by " - "editing the Redis configuration file, and setting the protected " + "editing the configuration file, and setting the protected " "mode option to 'no', and then restarting the server. " "3) If you started the server manually just for testing, restart " "it with the '--protected-mode no' option. " diff --git a/src/rdb.c b/src/rdb.c index 6384021350..b57cf44e7a 100644 --- a/src/rdb.c +++ b/src/rdb.c @@ -3081,7 +3081,7 @@ int rdbLoadRioWithLoadingCtx(rio *rdb, int rdbflags, rdbSaveInfo *rsi, rdbLoadin } else if (!strcasecmp(auxkey->ptr, "redis-ver")) { serverLog(LL_NOTICE, "Loading RDB produced by Redis version %s", (char *)auxval->ptr); } else if (!strcasecmp(auxkey->ptr, "valkey-ver")) { - serverLog(LL_NOTICE, "Loading RDB produced by valkey version %s", (char *)auxval->ptr); + serverLog(LL_NOTICE, "Loading RDB produced by Valkey version %s", (char *)auxval->ptr); } else if (!strcasecmp(auxkey->ptr, "ctime")) { time_t age = time(NULL) - strtol(auxval->ptr, NULL, 10); if (age < 0) age = 0; diff --git a/src/script_lua.c b/src/script_lua.c index cfe1959259..ff75b679cf 100644 --- a/src/script_lua.c +++ b/src/script_lua.c @@ -224,7 +224,7 @@ static void redisProtocolToLuaType_Int(void *ctx, long long val, const char *pro if (!lua_checkstack(lua, 1)) { /* Increase the Lua stack if needed, to make sure there is enough room * to push elements to the stack. On failure, exit with panic. */ - serverPanic("lua stack limit reach when parsing redis.call reply"); + serverPanic("lua stack limit reach when parsing server.call reply"); } lua_pushnumber(lua, (lua_Number)val); } @@ -240,7 +240,7 @@ static void redisProtocolToLuaType_NullBulkString(void *ctx, const char *proto, if (!lua_checkstack(lua, 1)) { /* Increase the Lua stack if needed, to make sure there is enough room * to push elements to the stack. On failure, exit with panic. */ - serverPanic("lua stack limit reach when parsing redis.call reply"); + serverPanic("lua stack limit reach when parsing server.call reply"); } lua_pushboolean(lua, 0); } @@ -255,7 +255,7 @@ static void redisProtocolToLuaType_NullArray(void *ctx, const char *proto, size_ if (!lua_checkstack(lua, 1)) { /* Increase the Lua stack if needed, to make sure there is enough room * to push elements to the stack. On failure, exit with panic. */ - serverPanic("lua stack limit reach when parsing redis.call reply"); + serverPanic("lua stack limit reach when parsing server.call reply"); } lua_pushboolean(lua, 0); } @@ -273,7 +273,7 @@ redisProtocolToLuaType_BulkString(void *ctx, const char *str, size_t len, const if (!lua_checkstack(lua, 1)) { /* Increase the Lua stack if needed, to make sure there is enough room * to push elements to the stack. On failure, exit with panic. */ - serverPanic("lua stack limit reach when parsing redis.call reply"); + serverPanic("lua stack limit reach when parsing server.call reply"); } lua_pushlstring(lua, str, len); } @@ -289,7 +289,7 @@ static void redisProtocolToLuaType_Status(void *ctx, const char *str, size_t len if (!lua_checkstack(lua, 3)) { /* Increase the Lua stack if needed, to make sure there is enough room * to push elements to the stack. On failure, exit with panic. */ - serverPanic("lua stack limit reach when parsing redis.call reply"); + serverPanic("lua stack limit reach when parsing server.call reply"); } lua_newtable(lua); lua_pushstring(lua, "ok"); @@ -308,7 +308,7 @@ static void redisProtocolToLuaType_Error(void *ctx, const char *str, size_t len, if (!lua_checkstack(lua, 3)) { /* Increase the Lua stack if needed, to make sure there is enough room * to push elements to the stack. On failure, exit with panic. */ - serverPanic("lua stack limit reach when parsing redis.call reply"); + serverPanic("lua stack limit reach when parsing server.call reply"); } sds err_msg = sdscatlen(sdsnew("-"), str, len); luaPushErrorBuff(lua, err_msg); @@ -326,7 +326,7 @@ static void redisProtocolToLuaType_Map(struct ReplyParser *parser, void *ctx, si if (!lua_checkstack(lua, 3)) { /* Increase the Lua stack if needed, to make sure there is enough room * to push elements to the stack. On failure, exit with panic. */ - serverPanic("lua stack limit reach when parsing redis.call reply"); + serverPanic("lua stack limit reach when parsing server.call reply"); } lua_newtable(lua); lua_pushstring(lua, "map"); @@ -348,7 +348,7 @@ static void redisProtocolToLuaType_Set(struct ReplyParser *parser, void *ctx, si if (!lua_checkstack(lua, 3)) { /* Increase the Lua stack if needed, to make sure there is enough room * to push elements to the stack. On failure, exit with panic. */ - serverPanic("lua stack limit reach when parsing redis.call reply"); + serverPanic("lua stack limit reach when parsing server.call reply"); } lua_newtable(lua); lua_pushstring(lua, "set"); @@ -362,7 +362,7 @@ static void redisProtocolToLuaType_Set(struct ReplyParser *parser, void *ctx, si * to push elements to the stack. On failure, exit with panic. * Notice that here we need to check the stack again because the recursive * call to redisProtocolToLuaType might have use the room allocated in the stack*/ - serverPanic("lua stack limit reach when parsing redis.call reply"); + serverPanic("lua stack limit reach when parsing server.call reply"); } lua_pushboolean(lua, 1); lua_settable(lua, -3); @@ -379,7 +379,7 @@ static void redisProtocolToLuaType_Array(struct ReplyParser *parser, void *ctx, if (!lua_checkstack(lua, 2)) { /* Increase the Lua stack if needed, to make sure there is enough room * to push elements to the stack. On failure, exit with panic. */ - serverPanic("lua stack limit reach when parsing redis.call reply"); + serverPanic("lua stack limit reach when parsing server.call reply"); } lua_newtable(lua); } @@ -422,7 +422,7 @@ static void redisProtocolToLuaType_VerbatimString(void *ctx, if (!lua_checkstack(lua, 5)) { /* Increase the Lua stack if needed, to make sure there is enough room * to push elements to the stack. On failure, exit with panic. */ - serverPanic("lua stack limit reach when parsing redis.call reply"); + serverPanic("lua stack limit reach when parsing server.call reply"); } lua_newtable(lua); lua_pushstring(lua, "verbatim_string"); @@ -448,7 +448,7 @@ redisProtocolToLuaType_BigNumber(void *ctx, const char *str, size_t len, const c if (!lua_checkstack(lua, 3)) { /* Increase the Lua stack if needed, to make sure there is enough room * to push elements to the stack. On failure, exit with panic. */ - serverPanic("lua stack limit reach when parsing redis.call reply"); + serverPanic("lua stack limit reach when parsing server.call reply"); } lua_newtable(lua); lua_pushstring(lua, "big_number"); @@ -467,7 +467,7 @@ static void redisProtocolToLuaType_Null(void *ctx, const char *proto, size_t pro if (!lua_checkstack(lua, 1)) { /* Increase the Lua stack if needed, to make sure there is enough room * to push elements to the stack. On failure, exit with panic. */ - serverPanic("lua stack limit reach when parsing redis.call reply"); + serverPanic("lua stack limit reach when parsing server.call reply"); } lua_pushnil(lua); } @@ -483,7 +483,7 @@ static void redisProtocolToLuaType_Bool(void *ctx, int val, const char *proto, s if (!lua_checkstack(lua, 1)) { /* Increase the Lua stack if needed, to make sure there is enough room * to push elements to the stack. On failure, exit with panic. */ - serverPanic("lua stack limit reach when parsing redis.call reply"); + serverPanic("lua stack limit reach when parsing server.call reply"); } lua_pushboolean(lua, val); } @@ -499,7 +499,7 @@ static void redisProtocolToLuaType_Double(void *ctx, double d, const char *proto if (!lua_checkstack(lua, 3)) { /* Increase the Lua stack if needed, to make sure there is enough room * to push elements to the stack. On failure, exit with panic. */ - serverPanic("lua stack limit reach when parsing redis.call reply"); + serverPanic("lua stack limit reach when parsing server.call reply"); } lua_newtable(lua); lua_pushstring(lua, "double"); @@ -508,7 +508,7 @@ static void redisProtocolToLuaType_Double(void *ctx, double d, const char *proto } /* This function is used in order to push an error on the Lua stack in the - * format used by redis.pcall to return errors, which is a lua table + * format used by server.pcall to return errors, which is a lua table * with an "err" field set to the error string including the error code. * Note that this table is never a valid reply by proper commands, * since the returned tables are otherwise always indexed by integers, never by strings. @@ -527,7 +527,7 @@ void luaPushErrorBuff(lua_State *lua, sds err_buffer) { /* There are two possible formats for the received `error` string: * 1) "-CODE msg": in this case we remove the leading '-' since we don't store it as part of the lua error format. * 2) "msg": in this case we prepend a generic 'ERR' code since all error statuses need some error code. - * We support format (1) so this function can reuse the error messages used in other places in redis. + * We support format (1) so this function can reuse the error messages used in other places. * We support format (2) so it'll be easy to pass descriptive errors to this function without worrying about format. */ if (err_buffer[0] == '-') { @@ -565,7 +565,7 @@ void luaPushError(lua_State *lua, const char *error) { } /* In case the error set into the Lua stack by luaPushError() was generated - * by the non-error-trapping version of redis.pcall(), which is redis.call(), + * by the non-error-trapping version of server.pcall(), which is server.call(), * this function will raise the Lua error so that the execution of the * script will be halted. */ int luaError(lua_State *lua) { @@ -759,7 +759,7 @@ static void luaReplyToRedisReply(client *c, client *script_client, lua_State *lu } /* --------------------------------------------------------------------------- - * Lua redis.* functions implementations. + * Lua server.* functions implementations. * ------------------------------------------------------------------------- */ void freeLuaRedisArgv(robj **argv, int argc, int argv_len); @@ -946,7 +946,7 @@ static int luaRedisGenericCommand(lua_State *lua, int raise_error) { redisProtocolToLuaType(lua, reply); /* If the debugger is active, log the reply from the server. */ - if (ldbIsEnabled()) ldbLogRedisReply(reply); + if (ldbIsEnabled()) ldbLogRespReply(reply); if (reply != c->buf) sdsfree(reply); c->reply_bytes = 0; @@ -998,17 +998,17 @@ static int luaRedisPcall(lua_State *lua) { return lua_gettop(lua); } -/* redis.call() */ +/* server.call() */ static int luaRedisCallCommand(lua_State *lua) { return luaRedisGenericCommand(lua, 1); } -/* redis.pcall() */ +/* server.pcall() */ static int luaRedisPCallCommand(lua_State *lua) { return luaRedisGenericCommand(lua, 0); } -/* This adds redis.sha1hex(string) to Lua scripts using the same hashing +/* This adds server.sha1hex(string) to Lua scripts using the same hashing * function used for sha1ing lua scripts. */ static int luaRedisSha1hexCommand(lua_State *lua) { int argc = lua_gettop(lua); @@ -1031,8 +1031,8 @@ static int luaRedisSha1hexCommand(lua_State *lua) { * passed as argument. This helper function is handy when returning * a RESP error or status reply from Lua: * - * return redis.error_reply("ERR Some Error") - * return redis.status_reply("ERR Some Error") + * return server.error_reply("ERR Some Error") + * return server.status_reply("ERR Some Error") */ static int luaRedisReturnSingleFieldTable(lua_State *lua, char *field) { if (lua_gettop(lua) != 1 || lua_type(lua, -1) != LUA_TSTRING) { @@ -1047,7 +1047,7 @@ static int luaRedisReturnSingleFieldTable(lua_State *lua, char *field) { return 1; } -/* redis.error_reply() */ +/* server.error_reply() */ static int luaRedisErrorReplyCommand(lua_State *lua) { if (lua_gettop(lua) != 1 || lua_type(lua, -1) != LUA_TSTRING) { luaPushError(lua, "wrong number or type of arguments"); @@ -1066,12 +1066,12 @@ static int luaRedisErrorReplyCommand(lua_State *lua) { return 1; } -/* redis.status_reply() */ +/* server.status_reply() */ static int luaRedisStatusReplyCommand(lua_State *lua) { return luaRedisReturnSingleFieldTable(lua, "ok"); } -/* redis.set_repl() +/* server.set_repl() * * Set the propagation of write commands executed in the context of the * script to on/off for AOF and slaves. */ @@ -1082,7 +1082,7 @@ static int luaRedisSetReplCommand(lua_State *lua) { serverAssert(rctx); /* Only supported inside script invocation */ if (argc != 1) { - luaPushError(lua, "redis.set_repl() requires one argument."); + luaPushError(lua, "server.set_repl() requires one argument."); return luaError(lua); } @@ -1096,7 +1096,7 @@ static int luaRedisSetReplCommand(lua_State *lua) { return 0; } -/* redis.acl_check_cmd() +/* server.acl_check_cmd() * * Checks ACL permissions for given command for the current user. */ static int luaRedisAclCheckCmdPermissionsCommand(lua_State *lua) { @@ -1132,14 +1132,14 @@ static int luaRedisAclCheckCmdPermissionsCommand(lua_State *lua) { } -/* redis.log() */ +/* server.log() */ static int luaLogCommand(lua_State *lua) { int j, argc = lua_gettop(lua); int level; sds log; if (argc < 2) { - luaPushError(lua, "redis.log() requires two arguments or more."); + luaPushError(lua, "server.log() requires two arguments or more."); return luaError(lua); } else if (!lua_isnumber(lua, -argc)) { luaPushError(lua, "First argument must be a number (log level)."); @@ -1169,14 +1169,14 @@ static int luaLogCommand(lua_State *lua) { return 0; } -/* redis.setresp() */ +/* server.setresp() */ static int luaSetResp(lua_State *lua) { scriptRunCtx *rctx = luaGetFromRegistry(lua, REGISTRY_RUN_CTX_NAME); serverAssert(rctx); /* Only supported inside script invocation */ int argc = lua_gettop(lua); if (argc != 1) { - luaPushError(lua, "redis.setresp() requires one argument."); + luaPushError(lua, "server.setresp() requires one argument."); return luaError(lua); } @@ -1378,7 +1378,7 @@ void luaRegisterVersion(lua_State *lua) { } void luaRegisterLogFunction(lua_State *lua) { - /* redis.log and log levels. */ + /* server.log and log levels. */ lua_pushstring(lua, "log"); lua_pushcfunction(lua, luaLogCommand); lua_settable(lua, -3); @@ -1400,7 +1400,7 @@ void luaRegisterLogFunction(lua_State *lua) { lua_settable(lua, -3); } -void luaRegisterRedisAPI(lua_State *lua) { +void luaRegisterServerAPI(lua_State *lua) { lua_pushvalue(lua, LUA_GLOBALSINDEX); luaSetAllowListProtection(lua); lua_pop(lua, 1); @@ -1413,12 +1413,12 @@ void luaRegisterRedisAPI(lua_State *lua) { /* Register the commands table and fields */ lua_newtable(lua); - /* redis.call */ + /* server.call */ lua_pushstring(lua, "call"); lua_pushcfunction(lua, luaRedisCallCommand); lua_settable(lua, -3); - /* redis.pcall */ + /* server.pcall */ lua_pushstring(lua, "pcall"); lua_pushcfunction(lua, luaRedisPCallCommand); lua_settable(lua, -3); @@ -1427,17 +1427,17 @@ void luaRegisterRedisAPI(lua_State *lua) { luaRegisterVersion(lua); - /* redis.setresp */ + /* server.setresp */ lua_pushstring(lua, "setresp"); lua_pushcfunction(lua, luaSetResp); lua_settable(lua, -3); - /* redis.sha1hex */ + /* server.sha1hex */ lua_pushstring(lua, "sha1hex"); lua_pushcfunction(lua, luaRedisSha1hexCommand); lua_settable(lua, -3); - /* redis.error_reply and redis.status_reply */ + /* server.error_reply and server.status_reply */ lua_pushstring(lua, "error_reply"); lua_pushcfunction(lua, luaRedisErrorReplyCommand); lua_settable(lua, -3); @@ -1445,7 +1445,7 @@ void luaRegisterRedisAPI(lua_State *lua) { lua_pushcfunction(lua, luaRedisStatusReplyCommand); lua_settable(lua, -3); - /* redis.set_repl and associated flags. */ + /* server.set_repl and associated flags. */ lua_pushstring(lua, "set_repl"); lua_pushcfunction(lua, luaRedisSetReplCommand); lua_settable(lua, -3); @@ -1470,7 +1470,7 @@ void luaRegisterRedisAPI(lua_State *lua) { lua_pushnumber(lua, PROPAGATE_AOF | PROPAGATE_REPL); lua_settable(lua, -3); - /* redis.acl_check_cmd */ + /* server.acl_check_cmd */ lua_pushstring(lua, "acl_check_cmd"); lua_pushcfunction(lua, luaRedisAclCheckCmdPermissionsCommand); lua_settable(lua, -3); diff --git a/src/script_lua.h b/src/script_lua.h index 8eec4b04f5..35edf46af6 100644 --- a/src/script_lua.h +++ b/src/script_lua.h @@ -66,7 +66,7 @@ typedef struct errorInfo { int ignore_err_stats_update; } errorInfo; -void luaRegisterRedisAPI(lua_State *lua); +void luaRegisterServerAPI(lua_State *lua); sds luaGetStringSds(lua_State *lua, int index); void luaRegisterGlobalProtectionFunction(lua_State *lua); void luaSetErrorMetatable(lua_State *lua); diff --git a/src/server.h b/src/server.h index 66f2c81c4d..30a2cace94 100644 --- a/src/server.h +++ b/src/server.h @@ -3465,7 +3465,7 @@ void freeLuaScriptsAsync(dict *lua_scripts, list *lua_scripts_lru_list, lua_Stat void freeFunctionsAsync(functionsLibCtx *lib_ctx); int ldbIsEnabled(void); void ldbLog(sds entry); -void ldbLogRedisReply(char *reply); +void ldbLogRespReply(char *reply); void sha1hex(char *digest, char *script, size_t len); unsigned long evalMemory(void); dict *evalScriptsDict(void); diff --git a/tests/integration/replication-4.tcl b/tests/integration/replication-4.tcl index 4370080b0f..d5b55b3b57 100644 --- a/tests/integration/replication-4.tcl +++ b/tests/integration/replication-4.tcl @@ -61,8 +61,8 @@ start_server {tags {"repl external:skip"}} { # Load some functions to be used later $master FUNCTION load replace {#!lua name=test - redis.register_function{function_name='f_default_flags', callback=function(keys, args) return redis.call('get',keys[1]) end, flags={}} - redis.register_function{function_name='f_no_writes', callback=function(keys, args) return redis.call('get',keys[1]) end, flags={'no-writes'}} + server.register_function{function_name='f_default_flags', callback=function(keys, args) return redis.call('get',keys[1]) end, flags={}} + server.register_function{function_name='f_no_writes', callback=function(keys, args) return redis.call('get',keys[1]) end, flags={'no-writes'}} } test {First server should have role slave after SLAVEOF} { diff --git a/tests/integration/replication.tcl b/tests/integration/replication.tcl index 2118a8acdb..e64394ad1b 100644 --- a/tests/integration/replication.tcl +++ b/tests/integration/replication.tcl @@ -574,12 +574,12 @@ foreach testType {Successful Aborted} { # Set a function value on replica to check status during loading, on failure and after swapping db $replica function load {#!lua name=test - redis.register_function('test', function() return 'hello1' end) + server.register_function('test', function() return 'hello1' end) } # Set a function value on master to check it reaches the replica when replication ends $master function load {#!lua name=test - redis.register_function('test', function() return 'hello2' end) + server.register_function('test', function() return 'hello2' end) } # Remember the sync_full stat before the client kill. @@ -727,7 +727,7 @@ test {diskless loading short read} { # Set a function value to check short read handling on functions r function load {#!lua name=test - redis.register_function('test', function() return 'hello1' end) + server.register_function('test', function() return 'hello1' end) } for {set k 0} {$k < 3} {incr k} { diff --git a/tests/integration/valkey-cli.tcl b/tests/integration/valkey-cli.tcl index 066a70a6a8..153c527055 100644 --- a/tests/integration/valkey-cli.tcl +++ b/tests/integration/valkey-cli.tcl @@ -451,7 +451,7 @@ if {!$::tls} { ;# fake_redis_node doesn't support TLS set dir [lindex [r config get dir] 1] assert_equal "OK" [r debug populate 100000 key 1000] - assert_equal "lib1" [r function load "#!lua name=lib1\nredis.register_function('func1', function() return 123 end)"] + assert_equal "lib1" [r function load "#!lua name=lib1\nserver.register_function('func1', function() return 123 end)"] if {$functions_only} { set args "--functions-rdb $dir/cli.rdb" } else { @@ -464,7 +464,7 @@ if {!$::tls} { ;# fake_redis_node doesn't support TLS file rename "$dir/cli.rdb" "$dir/dump.rdb" assert_equal "OK" [r set should-not-exist 1] - assert_equal "should_not_exist_func" [r function load "#!lua name=should_not_exist_func\nredis.register_function('should_not_exist_func', function() return 456 end)"] + assert_equal "should_not_exist_func" [r function load "#!lua name=should_not_exist_func\nserver.register_function('should_not_exist_func', function() return 456 end)"] assert_equal "OK" [r debug reload nosave] assert_equal {} [r get should-not-exist] assert_equal {{library_name lib1 engine LUA functions {{name func1 description {} flags {}}}}} [r function list] diff --git a/tests/unit/aofrw.tcl b/tests/unit/aofrw.tcl index cc7545265a..b5310edae4 100644 --- a/tests/unit/aofrw.tcl +++ b/tests/unit/aofrw.tcl @@ -194,7 +194,7 @@ start_server {tags {"aofrw external:skip"} overrides {aof-use-rdb-preamble no}} test "AOF rewrite functions" { r flushall r FUNCTION LOAD {#!lua name=test - redis.register_function('test', function() return 1 end) + server.register_function('test', function() return 1 end) } r bgrewriteaof waitForBgrewriteaof r diff --git a/tests/unit/cluster/cli.tcl b/tests/unit/cluster/cli.tcl index 62f0328352..f5599f6c5a 100644 --- a/tests/unit/cluster/cli.tcl +++ b/tests/unit/cluster/cli.tcl @@ -181,7 +181,7 @@ start_multiple_servers 5 [list overrides $base_conf] { # upload a function to all the cluster exec src/valkey-cli --cluster-yes --cluster call 127.0.0.1:[srv 0 port] \ FUNCTION LOAD {#!lua name=TEST - redis.register_function('test', function() return 'hello' end) + server.register_function('test', function() return 'hello' end) } # adding node to the cluster @@ -205,7 +205,7 @@ start_multiple_servers 5 [list overrides $base_conf] { # add function to node 5 assert_equal {TEST} [$node5_rd FUNCTION LOAD {#!lua name=TEST - redis.register_function('test', function() return 'hello' end) + server.register_function('test', function() return 'hello' end) }] # make sure functions was added to node 5 diff --git a/tests/unit/cluster/scripting.tcl b/tests/unit/cluster/scripting.tcl index 76aa882e83..1cf1421079 100644 --- a/tests/unit/cluster/scripting.tcl +++ b/tests/unit/cluster/scripting.tcl @@ -17,7 +17,7 @@ start_cluster 1 0 {tags {external:skip cluster}} { return 'OK' end - redis.register_function('test_cross_slot', test_cross_slot)} + server.register_function('test_cross_slot', test_cross_slot)} assert_error "ERR Script attempted to access keys that do not hash to the same slot*" {r FCALL test_cross_slot 0} } @@ -45,7 +45,7 @@ start_cluster 1 0 {tags {external:skip cluster}} { return 'OK' end - redis.register_function{function_name='test_cross_slot', callback=test_cross_slot, flags={ 'allow-cross-slot-keys' }}} + server.register_function{function_name='test_cross_slot', callback=test_cross_slot, flags={ 'allow-cross-slot-keys' }}} r FCALL test_cross_slot 0 # Retrieve data from different slot to verify data has been stored in the correct dictionary in cluster-enabled setup @@ -73,7 +73,7 @@ start_cluster 1 0 {tags {external:skip cluster}} { test "Function no-cluster flag" { R 0 function load {#!lua name=test - redis.register_function{function_name='f1', callback=function() return 'hello' end, flags={'no-cluster'}} + server.register_function{function_name='f1', callback=function() return 'hello' end, flags={'no-cluster'}} } catch {R 0 fcall f1 0} e assert_match {*Can not run script on cluster, 'no-cluster' flag is set*} $e diff --git a/tests/unit/functions.tcl b/tests/unit/functions.tcl index 4415b60e57..6a720419d3 100644 --- a/tests/unit/functions.tcl +++ b/tests/unit/functions.tcl @@ -1,9 +1,9 @@ proc get_function_code {args} { - return [format "#!%s name=%s\nredis.register_function('%s', function(KEYS, ARGV)\n %s \nend)" [lindex $args 0] [lindex $args 1] [lindex $args 2] [lindex $args 3]] + return [format "#!%s name=%s\nserver.register_function('%s', function(KEYS, ARGV)\n %s \nend)" [lindex $args 0] [lindex $args 1] [lindex $args 2] [lindex $args 3]] } proc get_no_writes_function_code {args} { - return [format "#!%s name=%s\nredis.register_function{function_name='%s', callback=function(KEYS, ARGV)\n %s \nend, flags={'no-writes'}}" [lindex $args 0] [lindex $args 1] [lindex $args 2] [lindex $args 3]] + return [format "#!%s name=%s\nserver.register_function{function_name='%s', callback=function(KEYS, ARGV)\n %s \nend, flags={'no-writes'}}" [lindex $args 0] [lindex $args 1] [lindex $args 2] [lindex $args 3]] } start_server {tags {"scripting"}} { @@ -433,7 +433,7 @@ test {FUNCTION can processes create, delete and flush commands in AOF when doing start_server {} { r config set appendonly yes waitForBgrewriteaof r - r FUNCTION LOAD "#!lua name=test\nredis.register_function('test', function() return 'hello' end)" + r FUNCTION LOAD "#!lua name=test\nserver.register_function('test', function() return 'hello' end)" r config set slave-read-only yes r slaveof 127.0.0.1 0 r debug loadaof @@ -447,7 +447,7 @@ test {FUNCTION can processes create, delete and flush commands in AOF when doing r slaveof no one assert_equal [r function list] {} - r FUNCTION LOAD "#!lua name=test\nredis.register_function('test', function() return 'hello' end)" + r FUNCTION LOAD "#!lua name=test\nserver.register_function('test', function() return 'hello' end)" r FUNCTION FLUSH r slaveof 127.0.0.1 0 @@ -463,7 +463,7 @@ start_server {tags {"scripting"}} { local function ping() return redis.call('ping') end - redis.register_function( + server.register_function( 'f1', function(keys, args) return ping() @@ -478,13 +478,13 @@ start_server {tags {"scripting"}} { local function add1(a) return a + 1 end - redis.register_function( + server.register_function( 'f1', function(keys, args) return add1(1) end ) - redis.register_function( + server.register_function( 'f2', function(keys, args) return add1(2) @@ -502,19 +502,19 @@ start_server {tags {"scripting"}} { local function add1(a) return a + 2 end - redis.register_function( + server.register_function( 'f1', function(keys, args) return add1(1) end ) - redis.register_function( + server.register_function( 'f2', 'not a function' ) } } e - assert_match {*second argument to redis.register_function must be a function*} $e + assert_match {*second argument to server.register_function must be a function*} $e assert_equal [r fcall f1 0] {2} assert_equal [r fcall f2 0] {3} } @@ -522,7 +522,7 @@ start_server {tags {"scripting"}} { test {LIBRARIES - test registration function name collision} { catch { r function load replace {#!lua name=lib2 - redis.register_function( + server.register_function( 'f1', function(keys, args) return 1 @@ -538,13 +538,13 @@ start_server {tags {"scripting"}} { test {LIBRARIES - test registration function name collision on same library} { catch { r function load replace {#!lua name=lib2 - redis.register_function( + server.register_function( 'f1', function(keys, args) return 1 end ) - redis.register_function( + server.register_function( 'f1', function(keys, args) return 1 @@ -558,43 +558,43 @@ start_server {tags {"scripting"}} { test {LIBRARIES - test registration with no argument} { catch { r function load replace {#!lua name=lib2 - redis.register_function() + server.register_function() } } e set _ $e - } {*wrong number of arguments to redis.register_function*} + } {*wrong number of arguments to server.register_function*} test {LIBRARIES - test registration with only name} { catch { r function load replace {#!lua name=lib2 - redis.register_function('f1') + server.register_function('f1') } } e set _ $e - } {*calling redis.register_function with a single argument is only applicable to Lua table*} + } {*calling server.register_function with a single argument is only applicable to Lua table*} test {LIBRARIES - test registration with to many arguments} { catch { r function load replace {#!lua name=lib2 - redis.register_function('f1', function() return 1 end, {}, 'description', 'extra arg') + server.register_function('f1', function() return 1 end, {}, 'description', 'extra arg') } } e set _ $e - } {*wrong number of arguments to redis.register_function*} + } {*wrong number of arguments to server.register_function*} test {LIBRARIES - test registration with no string name} { catch { r function load replace {#!lua name=lib2 - redis.register_function(nil, function() return 1 end) + server.register_function(nil, function() return 1 end) } } e set _ $e - } {*first argument to redis.register_function must be a string*} + } {*first argument to server.register_function must be a string*} test {LIBRARIES - test registration with wrong name format} { catch { r function load replace {#!lua name=lib2 - redis.register_function('test\0test', function() return 1 end) + server.register_function('test\0test', function() return 1 end) } } e set _ $e @@ -603,7 +603,7 @@ start_server {tags {"scripting"}} { test {LIBRARIES - test registration with empty name} { catch { r function load replace {#!lua name=lib2 - redis.register_function('', function() return 1 end) + server.register_function('', function() return 1 end) } } e set _ $e @@ -703,10 +703,10 @@ start_server {tags {"scripting"}} { test {LIBRARIES - register function inside a function} { r function load {#!lua name=lib - redis.register_function( + server.register_function( 'f1', function(keys, args) - redis.register_function( + server.register_function( 'f2', function(key, args) return 2 @@ -751,7 +751,7 @@ start_server {tags {"scripting"}} { test {LIBRARIES - named arguments} { r function load {#!lua name=lib - redis.register_function{ + server.register_function{ function_name='f1', callback=function() return 'hello' @@ -765,7 +765,7 @@ start_server {tags {"scripting"}} { test {LIBRARIES - named arguments, bad function name} { catch { r function load replace {#!lua name=lib - redis.register_function{ + server.register_function{ function_name=function() return 1 end, callback=function() return 'hello' @@ -775,12 +775,12 @@ start_server {tags {"scripting"}} { } } e set _ $e - } {*function_name argument given to redis.register_function must be a string*} + } {*function_name argument given to server.register_function must be a string*} test {LIBRARIES - named arguments, bad callback type} { catch { r function load replace {#!lua name=lib - redis.register_function{ + server.register_function{ function_name='f1', callback='bad', description='some desc' @@ -788,12 +788,12 @@ start_server {tags {"scripting"}} { } } e set _ $e - } {*callback argument given to redis.register_function must be a function*} + } {*callback argument given to server.register_function must be a function*} test {LIBRARIES - named arguments, bad description} { catch { r function load replace {#!lua name=lib - redis.register_function{ + server.register_function{ function_name='f1', callback=function() return 'hello' @@ -803,12 +803,12 @@ start_server {tags {"scripting"}} { } } e set _ $e - } {*description argument given to redis.register_function must be a string*} + } {*description argument given to server.register_function must be a string*} test {LIBRARIES - named arguments, unknown argument} { catch { r function load replace {#!lua name=lib - redis.register_function{ + server.register_function{ function_name='f1', callback=function() return 'hello' @@ -819,12 +819,12 @@ start_server {tags {"scripting"}} { } } e set _ $e - } {*unknown argument given to redis.register_function*} + } {*unknown argument given to server.register_function*} test {LIBRARIES - named arguments, missing function name} { catch { r function load replace {#!lua name=lib - redis.register_function{ + server.register_function{ callback=function() return 'hello' end, @@ -833,19 +833,19 @@ start_server {tags {"scripting"}} { } } e set _ $e - } {*redis.register_function must get a function name argument*} + } {*server.register_function must get a function name argument*} test {LIBRARIES - named arguments, missing callback} { catch { r function load replace {#!lua name=lib - redis.register_function{ + server.register_function{ function_name='f1', description='desc' } } } e set _ $e - } {*redis.register_function must get a callback argument*} + } {*server.register_function must get a callback argument*} test {FUNCTION - test function restore with function name collision} { r function flush @@ -853,19 +853,19 @@ start_server {tags {"scripting"}} { local function add1(a) return a + 1 end - redis.register_function( + server.register_function( 'f1', function(keys, args) return add1(1) end ) - redis.register_function( + server.register_function( 'f2', function(keys, args) return add1(2) end ) - redis.register_function( + server.register_function( 'f3', function(keys, args) return add1(3) @@ -877,7 +877,7 @@ start_server {tags {"scripting"}} { # load a library with different name but with the same function name r function load {#!lua name=lib1 - redis.register_function( + server.register_function( 'f6', function(keys, args) return 7 @@ -888,19 +888,19 @@ start_server {tags {"scripting"}} { local function add1(a) return a + 1 end - redis.register_function( + server.register_function( 'f4', function(keys, args) return add1(4) end ) - redis.register_function( + server.register_function( 'f5', function(keys, args) return add1(5) end ) - redis.register_function( + server.register_function( 'f3', function(keys, args) return add1(3) @@ -926,14 +926,14 @@ start_server {tags {"scripting"}} { test {FUNCTION - test function list with code} { r function flush r function load {#!lua name=library1 - redis.register_function('f6', function(keys, args) return 7 end) + server.register_function('f6', function(keys, args) return 7 end) } r function list withcode - } {{library_name library1 engine LUA functions {{name f6 description {} flags {}}} library_code {*redis.register_function('f6', function(keys, args) return 7 end)*}}} + } {{library_name library1 engine LUA functions {{name f6 description {} flags {}}} library_code {*server.register_function('f6', function(keys, args) return 7 end)*}}} test {FUNCTION - test function list with pattern} { r function load {#!lua name=lib1 - redis.register_function('f7', function(keys, args) return 7 end) + server.register_function('f7', function(keys, args) return 7 end) } r function list libraryname library* } {{library_name library1 engine LUA functions {{name f6 description {} flags {}}}}} @@ -961,14 +961,14 @@ start_server {tags {"scripting"}} { test {FUNCTION - verify OOM on function load and function restore} { r function flush r function load replace {#!lua name=test - redis.register_function('f1', function() return 1 end) + server.register_function('f1', function() return 1 end) } set payload [r function dump] r config set maxmemory 1 r function flush catch {r function load replace {#!lua name=test - redis.register_function('f1', function() return 1 end) + server.register_function('f1', function() return 1 end) }} e assert_match {*command not allowed when used memory*} $e @@ -981,7 +981,7 @@ start_server {tags {"scripting"}} { test {FUNCTION - verify allow-omm allows running any command} { r FUNCTION load replace {#!lua name=f1 - redis.register_function{ + server.register_function{ function_name='f1', callback=function() return redis.call('set', 'x', '1') end, flags={'allow-oom'} @@ -1000,18 +1000,18 @@ start_server {tags {"scripting"}} { start_server {tags {"scripting"}} { test {FUNCTION - wrong flags type named arguments} { catch {r function load replace {#!lua name=test - redis.register_function{ + server.register_function{ function_name = 'f1', callback = function() return 1 end, flags = 'bad flags type' } }} e set _ $e - } {*flags argument to redis.register_function must be a table representing function flags*} + } {*flags argument to server.register_function must be a table representing function flags*} test {FUNCTION - wrong flag type} { catch {r function load replace {#!lua name=test - redis.register_function{ + server.register_function{ function_name = 'f1', callback = function() return 1 end, flags = {function() return 1 end} @@ -1022,7 +1022,7 @@ start_server {tags {"scripting"}} { test {FUNCTION - unknown flag} { catch {r function load replace {#!lua name=test - redis.register_function{ + server.register_function{ function_name = 'f1', callback = function() return 1 end, flags = {'unknown'} @@ -1033,7 +1033,7 @@ start_server {tags {"scripting"}} { test {FUNCTION - write script on fcall_ro} { r function load replace {#!lua name=test - redis.register_function{ + server.register_function{ function_name = 'f1', callback = function() return redis.call('set', 'x', 1) end } @@ -1044,7 +1044,7 @@ start_server {tags {"scripting"}} { test {FUNCTION - write script with no-writes flag} { r function load replace {#!lua name=test - redis.register_function{ + server.register_function{ function_name = 'f1', callback = function() return redis.call('set', 'x', 1) end, flags = {'no-writes'} @@ -1056,7 +1056,7 @@ start_server {tags {"scripting"}} { test {FUNCTION - deny oom} { r FUNCTION load replace {#!lua name=test - redis.register_function('f1', function() return redis.call('set', 'x', '1') end) + server.register_function('f1', function() return redis.call('set', 'x', '1') end) } r config set maxmemory 1 @@ -1069,7 +1069,7 @@ start_server {tags {"scripting"}} { test {FUNCTION - deny oom on no-writes function} { r FUNCTION load replace {#!lua name=test - redis.register_function{function_name='f1', callback=function() return 'hello' end, flags={'no-writes'}} + server.register_function{function_name='f1', callback=function() return 'hello' end, flags={'no-writes'}} } r config set maxmemory 1 @@ -1082,10 +1082,10 @@ start_server {tags {"scripting"}} { test {FUNCTION - allow stale} { r FUNCTION load replace {#!lua name=test - redis.register_function{function_name='f1', callback=function() return 'hello' end, flags={'no-writes'}} - redis.register_function{function_name='f2', callback=function() return 'hello' end, flags={'allow-stale', 'no-writes'}} - redis.register_function{function_name='f3', callback=function() return redis.call('get', 'x') end, flags={'allow-stale', 'no-writes'}} - redis.register_function{function_name='f4', callback=function() return redis.call('info', 'server') end, flags={'allow-stale', 'no-writes'}} + server.register_function{function_name='f1', callback=function() return 'hello' end, flags={'no-writes'}} + server.register_function{function_name='f2', callback=function() return 'hello' end, flags={'allow-stale', 'no-writes'}} + server.register_function{function_name='f3', callback=function() return redis.call('get', 'x') end, flags={'allow-stale', 'no-writes'}} + server.register_function{function_name='f4', callback=function() return redis.call('info', 'server') end, flags={'allow-stale', 'no-writes'}} } r config set replica-serve-stale-data no @@ -1110,13 +1110,13 @@ start_server {tags {"scripting"}} { r FUNCTION load replace {#!lua name=test local version = redis.REDIS_VERSION_NUM - redis.register_function{function_name='get_version_v1', callback=function() + server.register_function{function_name='get_version_v1', callback=function() return string.format('%s.%s.%s', bit.band(bit.rshift(version, 16), 0x000000ff), bit.band(bit.rshift(version, 8), 0x000000ff), bit.band(version, 0x000000ff)) end} - redis.register_function{function_name='get_version_v2', callback=function() return redis.REDIS_VERSION end} + server.register_function{function_name='get_version_v2', callback=function() return redis.REDIS_VERSION end} } catch {[r fcall f1 0]} e @@ -1127,12 +1127,12 @@ start_server {tags {"scripting"}} { r FUNCTION FLUSH r FUNCTION load {#!lua name=test1 - redis.register_function('f1', function() return 1 end) - redis.register_function('f2', function() return 1 end) + server.register_function('f1', function() return 1 end) + server.register_function('f2', function() return 1 end) } r FUNCTION load {#!lua name=test2 - redis.register_function('f3', function() return 1 end) + server.register_function('f3', function() return 1 end) } r function stats @@ -1152,12 +1152,12 @@ start_server {tags {"scripting"}} { r FUNCTION FLUSH r FUNCTION load {#!lua name=test1 - redis.register_function('f1', function() return 1 end) - redis.register_function('f2', function() return 1 end) + server.register_function('f1', function() return 1 end) + server.register_function('f2', function() return 1 end) } catch {r FUNCTION load {#!lua name=test1 - redis.register_function('f3', function() return 1 end) + server.register_function('f3', function() return 1 end) }} e assert_match "*Library 'test1' already exists*" $e @@ -1172,35 +1172,35 @@ start_server {tags {"scripting"}} { test {FUNCTION - function test empty engine} { catch {r function load replace {#! name=test - redis.register_function('foo', function() return 1 end) + server.register_function('foo', function() return 1 end) }} e set _ $e } {ERR Engine '' not found} test {FUNCTION - function test unknown metadata value} { catch {r function load replace {#!lua name=test foo=bar - redis.register_function('foo', function() return 1 end) + server.register_function('foo', function() return 1 end) }} e set _ $e } {ERR Invalid metadata value given: foo=bar} test {FUNCTION - function test no name} { catch {r function load replace {#!lua - redis.register_function('foo', function() return 1 end) + server.register_function('foo', function() return 1 end) }} e set _ $e } {ERR Library name was not given} test {FUNCTION - function test multiple names} { catch {r function load replace {#!lua name=foo name=bar - redis.register_function('foo', function() return 1 end) + server.register_function('foo', function() return 1 end) }} e set _ $e } {ERR Invalid metadata value, name argument was given multiple times} test {FUNCTION - function test name with quotes} { r function load replace {#!lua name="foo" - redis.register_function('foo', function() return 1 end) + server.register_function('foo', function() return 1 end) } } {foo} @@ -1208,7 +1208,7 @@ start_server {tags {"scripting"}} { r FUNCTION FLUSH r FUNCTION load {#!lua name=test1 - redis.register_function('f1', function() + server.register_function('f1', function() mt = getmetatable(_G) original_globals = mt.__index original_globals['redis'] = function() return 1 end diff --git a/tests/unit/introspection.tcl b/tests/unit/introspection.tcl index 02aca9e97d..8ceb03b502 100644 --- a/tests/unit/introspection.tcl +++ b/tests/unit/introspection.tcl @@ -311,7 +311,7 @@ start_server {tags {"introspection"}} { test {MONITOR can log commands issued by functions} { r function load replace {#!lua name=test - redis.register_function('test', function() return redis.call('set', 'foo', 'bar') end) + server.register_function('test', function() return redis.call('set', 'foo', 'bar') end) } set rd [valkey_deferring_client] $rd monitor diff --git a/tests/unit/moduleapi/misc.tcl b/tests/unit/moduleapi/misc.tcl index 041149eb80..9e0ea72456 100644 --- a/tests/unit/moduleapi/misc.tcl +++ b/tests/unit/moduleapi/misc.tcl @@ -45,7 +45,7 @@ start_server {overrides {save {900 1}} tags {"modules"}} { test {test RedisModule_ResetDataset do not reset functions} { r function load {#!lua name=lib - redis.register_function('test', function() return 1 end) + server.register_function('test', function() return 1 end) } assert_equal [r function list] {{library_name lib engine LUA functions {{name test description {} flags {}}}}} r test.flushall diff --git a/tests/unit/pause.tcl b/tests/unit/pause.tcl index 3698e9e064..38c13afc46 100644 --- a/tests/unit/pause.tcl +++ b/tests/unit/pause.tcl @@ -133,7 +133,7 @@ start_server {tags {"pause network"}} { r set x y # create a function for later r FUNCTION load replace {#!lua name=f1 - redis.register_function{ + server.register_function{ function_name='f1', callback=function() return "hello" end, flags={'no-writes'} diff --git a/tests/unit/scripting.tcl b/tests/unit/scripting.tcl index a4ab545803..0b7206e2a0 100644 --- a/tests/unit/scripting.tcl +++ b/tests/unit/scripting.tcl @@ -1189,7 +1189,7 @@ start_server {tags {"scripting"}} { set buf "*3\r\n\$4\r\neval\r\n\$33\r\nwhile 1 do redis.call('ping') end\r\n\$1\r\n0\r\n" append buf "*1\r\n\$4\r\nping\r\n" } else { - set buf "*4\r\n\$8\r\nfunction\r\n\$4\r\nload\r\n\$7\r\nreplace\r\n\$97\r\n#!lua name=test\nredis.register_function('test', function() while 1 do redis.call('ping') end end)\r\n" + set buf "*4\r\n\$8\r\nfunction\r\n\$4\r\nload\r\n\$7\r\nreplace\r\n\$99\r\n#!lua name=test\nserver.register_function('test', function() while 1 do server.call('ping') end end)\r\n" append buf "*3\r\n\$5\r\nfcall\r\n\$4\r\ntest\r\n\$1\r\n0\r\n" append buf "*1\r\n\$4\r\nping\r\n" }