mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-21 23:58:51 -05:00
all: fix up remaining lua references to redis
The test suite still needs to be updated, though.
This commit is contained in:
parent
d47ce2f240
commit
c3d36a8bcb
106
src/eval.c
106
src/eval.c
@ -111,7 +111,7 @@ void sha1hex(char *digest, char *script, size_t len) {
|
|||||||
* Allows to stop execution during a debugging session from within
|
* Allows to stop execution during a debugging session from within
|
||||||
* the Lua code implementation, like if a breakpoint was set in the code
|
* the Lua code implementation, like if a breakpoint was set in the code
|
||||||
* immediately after the function. */
|
* immediately after the function. */
|
||||||
int luaRedisBreakpointCommand(lua_State *lua) {
|
int luaRedictBreakpointCommand(lua_State *lua) {
|
||||||
if (ldb.active) {
|
if (ldb.active) {
|
||||||
ldb.luabp = 1;
|
ldb.luabp = 1;
|
||||||
lua_pushboolean(lua,1);
|
lua_pushboolean(lua,1);
|
||||||
@ -126,7 +126,7 @@ int luaRedisBreakpointCommand(lua_State *lua) {
|
|||||||
* Log a string message into the output console.
|
* Log a string message into the output console.
|
||||||
* Can take multiple arguments that will be separated by commas.
|
* Can take multiple arguments that will be separated by commas.
|
||||||
* Nothing is returned to the caller. */
|
* Nothing is returned to the caller. */
|
||||||
int luaRedisDebugCommand(lua_State *lua) {
|
int luaRedictDebugCommand(lua_State *lua) {
|
||||||
if (!ldb.active) return 0;
|
if (!ldb.active) return 0;
|
||||||
int argc = lua_gettop(lua);
|
int argc = lua_gettop(lua);
|
||||||
sds log = sdscatprintf(sdsempty(),"<debug> line %d: ", ldb.currentline);
|
sds log = sdscatprintf(sdsempty(),"<debug> line %d: ", ldb.currentline);
|
||||||
@ -145,7 +145,7 @@ int luaRedisDebugCommand(lua_State *lua) {
|
|||||||
* a write command so far, and returns true. Otherwise if the script
|
* a write command so far, and returns true. Otherwise if the script
|
||||||
* already started to write, returns false and stick to whole scripts
|
* already started to write, returns false and stick to whole scripts
|
||||||
* replication, which is our default. */
|
* replication, which is our default. */
|
||||||
int luaRedisReplicateCommandsCommand(lua_State *lua) {
|
int luaRedictReplicateCommandsCommand(lua_State *lua) {
|
||||||
lua_pushboolean(lua,1);
|
lua_pushboolean(lua,1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -181,19 +181,19 @@ void scriptingInit(int setup) {
|
|||||||
/* register debug commands */
|
/* register debug commands */
|
||||||
lua_getglobal(lua,REDICT_API_NAME);
|
lua_getglobal(lua,REDICT_API_NAME);
|
||||||
|
|
||||||
/* redis.breakpoint */
|
/* redict.breakpoint */
|
||||||
lua_pushstring(lua,"breakpoint");
|
lua_pushstring(lua,"breakpoint");
|
||||||
lua_pushcfunction(lua,luaRedisBreakpointCommand);
|
lua_pushcfunction(lua,luaRedictBreakpointCommand);
|
||||||
lua_settable(lua,-3);
|
lua_settable(lua,-3);
|
||||||
|
|
||||||
/* redis.debug */
|
/* redict.debug */
|
||||||
lua_pushstring(lua,"debug");
|
lua_pushstring(lua,"debug");
|
||||||
lua_pushcfunction(lua,luaRedisDebugCommand);
|
lua_pushcfunction(lua,luaRedictDebugCommand);
|
||||||
lua_settable(lua,-3);
|
lua_settable(lua,-3);
|
||||||
|
|
||||||
/* redis.replicate_commands */
|
/* redict.replicate_commands */
|
||||||
lua_pushstring(lua, "replicate_commands");
|
lua_pushstring(lua, "replicate_commands");
|
||||||
lua_pushcfunction(lua, luaRedisReplicateCommandsCommand);
|
lua_pushcfunction(lua, luaRedictReplicateCommandsCommand);
|
||||||
lua_settable(lua, -3);
|
lua_settable(lua, -3);
|
||||||
|
|
||||||
lua_setglobal(lua,REDICT_API_NAME);
|
lua_setglobal(lua,REDICT_API_NAME);
|
||||||
@ -201,19 +201,19 @@ void scriptingInit(int setup) {
|
|||||||
/* register debug commands */
|
/* register debug commands */
|
||||||
lua_getglobal(lua,REDICT_API_NAME);
|
lua_getglobal(lua,REDICT_API_NAME);
|
||||||
|
|
||||||
/* redis.breakpoint */
|
/* redict.breakpoint */
|
||||||
lua_pushstring(lua,"breakpoint");
|
lua_pushstring(lua,"breakpoint");
|
||||||
lua_pushcfunction(lua,luaRedisBreakpointCommand);
|
lua_pushcfunction(lua,luaRedictBreakpointCommand);
|
||||||
lua_settable(lua,-3);
|
lua_settable(lua,-3);
|
||||||
|
|
||||||
/* redis.debug */
|
/* redict.debug */
|
||||||
lua_pushstring(lua,"debug");
|
lua_pushstring(lua,"debug");
|
||||||
lua_pushcfunction(lua,luaRedisDebugCommand);
|
lua_pushcfunction(lua,luaRedictDebugCommand);
|
||||||
lua_settable(lua,-3);
|
lua_settable(lua,-3);
|
||||||
|
|
||||||
/* redis.replicate_commands */
|
/* redict.replicate_commands */
|
||||||
lua_pushstring(lua, "replicate_commands");
|
lua_pushstring(lua, "replicate_commands");
|
||||||
lua_pushcfunction(lua, luaRedisReplicateCommandsCommand);
|
lua_pushcfunction(lua, luaRedictReplicateCommandsCommand);
|
||||||
lua_settable(lua, -3);
|
lua_settable(lua, -3);
|
||||||
|
|
||||||
lua_setglobal(lua,REDICT_API_NAME);
|
lua_setglobal(lua,REDICT_API_NAME);
|
||||||
@ -1229,48 +1229,48 @@ void ldbLogStackValue(lua_State *lua, char *prefix) {
|
|||||||
ldbLogWithMaxLen(s);
|
ldbLogWithMaxLen(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *ldbRedisProtocolToHuman_Int(sds *o, char *reply);
|
char *ldbRedictProtocolToHuman_Int(sds *o, char *reply);
|
||||||
char *ldbRedisProtocolToHuman_Bulk(sds *o, char *reply);
|
char *ldbRedictProtocolToHuman_Bulk(sds *o, char *reply);
|
||||||
char *ldbRedisProtocolToHuman_Status(sds *o, char *reply);
|
char *ldbRedictProtocolToHuman_Status(sds *o, char *reply);
|
||||||
char *ldbRedisProtocolToHuman_MultiBulk(sds *o, char *reply);
|
char *ldbRedictProtocolToHuman_MultiBulk(sds *o, char *reply);
|
||||||
char *ldbRedisProtocolToHuman_Set(sds *o, char *reply);
|
char *ldbRedictProtocolToHuman_Set(sds *o, char *reply);
|
||||||
char *ldbRedisProtocolToHuman_Map(sds *o, char *reply);
|
char *ldbRedictProtocolToHuman_Map(sds *o, char *reply);
|
||||||
char *ldbRedisProtocolToHuman_Null(sds *o, char *reply);
|
char *ldbRedictProtocolToHuman_Null(sds *o, char *reply);
|
||||||
char *ldbRedisProtocolToHuman_Bool(sds *o, char *reply);
|
char *ldbRedictProtocolToHuman_Bool(sds *o, char *reply);
|
||||||
char *ldbRedisProtocolToHuman_Double(sds *o, char *reply);
|
char *ldbRedictProtocolToHuman_Double(sds *o, char *reply);
|
||||||
|
|
||||||
/* Get Redict protocol from 'reply' and appends it in human readable form to
|
/* Get Redict protocol from 'reply' and appends it in human readable form to
|
||||||
* the passed SDS string 'o'.
|
* the passed SDS string 'o'.
|
||||||
*
|
*
|
||||||
* Note that the SDS string is passed by reference (pointer of pointer to
|
* 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*) so that we can return a modified pointer, as for SDS semantics. */
|
||||||
char *ldbRedisProtocolToHuman(sds *o, char *reply) {
|
char *ldbRedictProtocolToHuman(sds *o, char *reply) {
|
||||||
char *p = reply;
|
char *p = reply;
|
||||||
switch(*p) {
|
switch(*p) {
|
||||||
case ':': p = ldbRedisProtocolToHuman_Int(o,reply); break;
|
case ':': p = ldbRedictProtocolToHuman_Int(o,reply); break;
|
||||||
case '$': p = ldbRedisProtocolToHuman_Bulk(o,reply); break;
|
case '$': p = ldbRedictProtocolToHuman_Bulk(o,reply); break;
|
||||||
case '+': p = ldbRedisProtocolToHuman_Status(o,reply); break;
|
case '+': p = ldbRedictProtocolToHuman_Status(o,reply); break;
|
||||||
case '-': p = ldbRedisProtocolToHuman_Status(o,reply); break;
|
case '-': p = ldbRedictProtocolToHuman_Status(o,reply); break;
|
||||||
case '*': p = ldbRedisProtocolToHuman_MultiBulk(o,reply); break;
|
case '*': p = ldbRedictProtocolToHuman_MultiBulk(o,reply); break;
|
||||||
case '~': p = ldbRedisProtocolToHuman_Set(o,reply); break;
|
case '~': p = ldbRedictProtocolToHuman_Set(o,reply); break;
|
||||||
case '%': p = ldbRedisProtocolToHuman_Map(o,reply); break;
|
case '%': p = ldbRedictProtocolToHuman_Map(o,reply); break;
|
||||||
case '_': p = ldbRedisProtocolToHuman_Null(o,reply); break;
|
case '_': p = ldbRedictProtocolToHuman_Null(o,reply); break;
|
||||||
case '#': p = ldbRedisProtocolToHuman_Bool(o,reply); break;
|
case '#': p = ldbRedictProtocolToHuman_Bool(o,reply); break;
|
||||||
case ',': p = ldbRedisProtocolToHuman_Double(o,reply); break;
|
case ',': p = ldbRedictProtocolToHuman_Double(o,reply); break;
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The following functions are helpers for ldbRedisProtocolToHuman(), each
|
/* The following functions are helpers for ldbRedictProtocolToHuman(), each
|
||||||
* take care of a given Redict return type. */
|
* take care of a given Redict return type. */
|
||||||
|
|
||||||
char *ldbRedisProtocolToHuman_Int(sds *o, char *reply) {
|
char *ldbRedictProtocolToHuman_Int(sds *o, char *reply) {
|
||||||
char *p = strchr(reply+1,'\r');
|
char *p = strchr(reply+1,'\r');
|
||||||
*o = sdscatlen(*o,reply+1,p-reply-1);
|
*o = sdscatlen(*o,reply+1,p-reply-1);
|
||||||
return p+2;
|
return p+2;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *ldbRedisProtocolToHuman_Bulk(sds *o, char *reply) {
|
char *ldbRedictProtocolToHuman_Bulk(sds *o, char *reply) {
|
||||||
char *p = strchr(reply+1,'\r');
|
char *p = strchr(reply+1,'\r');
|
||||||
long long bulklen;
|
long long bulklen;
|
||||||
|
|
||||||
@ -1284,14 +1284,14 @@ char *ldbRedisProtocolToHuman_Bulk(sds *o, char *reply) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *ldbRedisProtocolToHuman_Status(sds *o, char *reply) {
|
char *ldbRedictProtocolToHuman_Status(sds *o, char *reply) {
|
||||||
char *p = strchr(reply+1,'\r');
|
char *p = strchr(reply+1,'\r');
|
||||||
|
|
||||||
*o = sdscatrepr(*o,reply,p-reply);
|
*o = sdscatrepr(*o,reply,p-reply);
|
||||||
return p+2;
|
return p+2;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *ldbRedisProtocolToHuman_MultiBulk(sds *o, char *reply) {
|
char *ldbRedictProtocolToHuman_MultiBulk(sds *o, char *reply) {
|
||||||
char *p = strchr(reply+1,'\r');
|
char *p = strchr(reply+1,'\r');
|
||||||
long long mbulklen;
|
long long mbulklen;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
@ -1304,14 +1304,14 @@ char *ldbRedisProtocolToHuman_MultiBulk(sds *o, char *reply) {
|
|||||||
}
|
}
|
||||||
*o = sdscatlen(*o,"[",1);
|
*o = sdscatlen(*o,"[",1);
|
||||||
for (j = 0; j < mbulklen; j++) {
|
for (j = 0; j < mbulklen; j++) {
|
||||||
p = ldbRedisProtocolToHuman(o,p);
|
p = ldbRedictProtocolToHuman(o,p);
|
||||||
if (j != mbulklen-1) *o = sdscatlen(*o,",",1);
|
if (j != mbulklen-1) *o = sdscatlen(*o,",",1);
|
||||||
}
|
}
|
||||||
*o = sdscatlen(*o,"]",1);
|
*o = sdscatlen(*o,"]",1);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *ldbRedisProtocolToHuman_Set(sds *o, char *reply) {
|
char *ldbRedictProtocolToHuman_Set(sds *o, char *reply) {
|
||||||
char *p = strchr(reply+1,'\r');
|
char *p = strchr(reply+1,'\r');
|
||||||
long long mbulklen;
|
long long mbulklen;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
@ -1320,14 +1320,14 @@ char *ldbRedisProtocolToHuman_Set(sds *o, char *reply) {
|
|||||||
p += 2;
|
p += 2;
|
||||||
*o = sdscatlen(*o,"~(",2);
|
*o = sdscatlen(*o,"~(",2);
|
||||||
for (j = 0; j < mbulklen; j++) {
|
for (j = 0; j < mbulklen; j++) {
|
||||||
p = ldbRedisProtocolToHuman(o,p);
|
p = ldbRedictProtocolToHuman(o,p);
|
||||||
if (j != mbulklen-1) *o = sdscatlen(*o,",",1);
|
if (j != mbulklen-1) *o = sdscatlen(*o,",",1);
|
||||||
}
|
}
|
||||||
*o = sdscatlen(*o,")",1);
|
*o = sdscatlen(*o,")",1);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *ldbRedisProtocolToHuman_Map(sds *o, char *reply) {
|
char *ldbRedictProtocolToHuman_Map(sds *o, char *reply) {
|
||||||
char *p = strchr(reply+1,'\r');
|
char *p = strchr(reply+1,'\r');
|
||||||
long long mbulklen;
|
long long mbulklen;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
@ -1336,22 +1336,22 @@ char *ldbRedisProtocolToHuman_Map(sds *o, char *reply) {
|
|||||||
p += 2;
|
p += 2;
|
||||||
*o = sdscatlen(*o,"{",1);
|
*o = sdscatlen(*o,"{",1);
|
||||||
for (j = 0; j < mbulklen; j++) {
|
for (j = 0; j < mbulklen; j++) {
|
||||||
p = ldbRedisProtocolToHuman(o,p);
|
p = ldbRedictProtocolToHuman(o,p);
|
||||||
*o = sdscatlen(*o," => ",4);
|
*o = sdscatlen(*o," => ",4);
|
||||||
p = ldbRedisProtocolToHuman(o,p);
|
p = ldbRedictProtocolToHuman(o,p);
|
||||||
if (j != mbulklen-1) *o = sdscatlen(*o,",",1);
|
if (j != mbulklen-1) *o = sdscatlen(*o,",",1);
|
||||||
}
|
}
|
||||||
*o = sdscatlen(*o,"}",1);
|
*o = sdscatlen(*o,"}",1);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *ldbRedisProtocolToHuman_Null(sds *o, char *reply) {
|
char *ldbRedictProtocolToHuman_Null(sds *o, char *reply) {
|
||||||
char *p = strchr(reply+1,'\r');
|
char *p = strchr(reply+1,'\r');
|
||||||
*o = sdscatlen(*o,"(null)",6);
|
*o = sdscatlen(*o,"(null)",6);
|
||||||
return p+2;
|
return p+2;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *ldbRedisProtocolToHuman_Bool(sds *o, char *reply) {
|
char *ldbRedictProtocolToHuman_Bool(sds *o, char *reply) {
|
||||||
char *p = strchr(reply+1,'\r');
|
char *p = strchr(reply+1,'\r');
|
||||||
if (reply[1] == 't')
|
if (reply[1] == 't')
|
||||||
*o = sdscatlen(*o,"#true",5);
|
*o = sdscatlen(*o,"#true",5);
|
||||||
@ -1360,7 +1360,7 @@ char *ldbRedisProtocolToHuman_Bool(sds *o, char *reply) {
|
|||||||
return p+2;
|
return p+2;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *ldbRedisProtocolToHuman_Double(sds *o, char *reply) {
|
char *ldbRedictProtocolToHuman_Double(sds *o, char *reply) {
|
||||||
char *p = strchr(reply+1,'\r');
|
char *p = strchr(reply+1,'\r');
|
||||||
*o = sdscatlen(*o,"(double) ",9);
|
*o = sdscatlen(*o,"(double) ",9);
|
||||||
*o = sdscatlen(*o,reply+1,p-reply-1);
|
*o = sdscatlen(*o,reply+1,p-reply-1);
|
||||||
@ -1372,7 +1372,7 @@ char *ldbRedisProtocolToHuman_Double(sds *o, char *reply) {
|
|||||||
* used as prefix, it gets truncated. */
|
* used as prefix, it gets truncated. */
|
||||||
void ldbLogRedictReply(char *reply) {
|
void ldbLogRedictReply(char *reply) {
|
||||||
sds log = sdsnew("<reply> ");
|
sds log = sdsnew("<reply> ");
|
||||||
ldbRedisProtocolToHuman(&log,reply);
|
ldbRedictProtocolToHuman(&log,reply);
|
||||||
ldbLogWithMaxLen(log);
|
ldbLogWithMaxLen(log);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1514,7 +1514,7 @@ void ldbEval(lua_State *lua, sds *argv, int argc) {
|
|||||||
* the implementation very simple: we just call the Lua redict.call() command
|
* the implementation very simple: we just call the Lua redict.call() command
|
||||||
* implementation, with ldb.step enabled, so as a side effect the Redict command
|
* implementation, with ldb.step enabled, so as a side effect the Redict command
|
||||||
* and its reply are logged. */
|
* and its reply are logged. */
|
||||||
void ldbRedis(lua_State *lua, sds *argv, int argc) {
|
void ldbRedict(lua_State *lua, sds *argv, int argc) {
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
if (!lua_checkstack(lua, argc + 1)) {
|
if (!lua_checkstack(lua, argc + 1)) {
|
||||||
@ -1674,11 +1674,11 @@ ldbLog(sdsnew(" next line of code."));
|
|||||||
luaError(lua);
|
luaError(lua);
|
||||||
} else if (argc > 1 &&
|
} else if (argc > 1 &&
|
||||||
(!strcasecmp(argv[0],"r") || !strcasecmp(argv[0],"redis"))) {
|
(!strcasecmp(argv[0],"r") || !strcasecmp(argv[0],"redis"))) {
|
||||||
ldbRedis(lua,argv,argc);
|
ldbRedict(lua,argv,argc);
|
||||||
ldbSendLogs();
|
ldbSendLogs();
|
||||||
} else if (argc > 1 &&
|
} else if (argc > 1 &&
|
||||||
(!strcasecmp(argv[0],"r") || !strcasecmp(argv[0],"redict"))) {
|
(!strcasecmp(argv[0],"r") || !strcasecmp(argv[0],"redict"))) {
|
||||||
ldbRedis(lua,argv,argc);
|
ldbRedict(lua,argv,argc);
|
||||||
ldbSendLogs();
|
ldbSendLogs();
|
||||||
} else if ((!strcasecmp(argv[0],"p") || !strcasecmp(argv[0],"print"))) {
|
} else if ((!strcasecmp(argv[0],"p") || !strcasecmp(argv[0],"print"))) {
|
||||||
if (argc == 2)
|
if (argc == 2)
|
||||||
|
@ -254,7 +254,7 @@ static int luaRegisterFunctionReadNamedArgs(lua_State *lua, registerFunctionArgs
|
|||||||
luaFunctionCtx *lua_f_ctx = NULL;
|
luaFunctionCtx *lua_f_ctx = NULL;
|
||||||
uint64_t flags = 0;
|
uint64_t flags = 0;
|
||||||
if (!lua_istable(lua, 1)) {
|
if (!lua_istable(lua, 1)) {
|
||||||
err = "calling redis.register_function with a single argument is only applicable to Lua table (representing named arguments).";
|
err = "calling redict.register_function with a single argument is only applicable to Lua table (representing named arguments).";
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,23 +263,23 @@ static int luaRegisterFunctionReadNamedArgs(lua_State *lua, registerFunctionArgs
|
|||||||
while (lua_next(lua, -2)) {
|
while (lua_next(lua, -2)) {
|
||||||
/* Stack now: table, key, value */
|
/* Stack now: table, key, value */
|
||||||
if (!lua_isstring(lua, -2)) {
|
if (!lua_isstring(lua, -2)) {
|
||||||
err = "named argument key given to redis.register_function is not a string";
|
err = "named argument key given to redict.register_function is not a string";
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
const char *key = lua_tostring(lua, -2);
|
const char *key = lua_tostring(lua, -2);
|
||||||
if (!strcasecmp(key, "function_name")) {
|
if (!strcasecmp(key, "function_name")) {
|
||||||
if (!(name = luaGetStringSds(lua, -1))) {
|
if (!(name = luaGetStringSds(lua, -1))) {
|
||||||
err = "function_name argument given to redis.register_function must be a string";
|
err = "function_name argument given to redict.register_function must be a string";
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
} else if (!strcasecmp(key, "description")) {
|
} else if (!strcasecmp(key, "description")) {
|
||||||
if (!(desc = luaGetStringSds(lua, -1))) {
|
if (!(desc = luaGetStringSds(lua, -1))) {
|
||||||
err = "description argument given to redis.register_function must be a string";
|
err = "description argument given to redict.register_function must be a string";
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
} else if (!strcasecmp(key, "callback")) {
|
} else if (!strcasecmp(key, "callback")) {
|
||||||
if (!lua_isfunction(lua, -1)) {
|
if (!lua_isfunction(lua, -1)) {
|
||||||
err = "callback argument given to redis.register_function must be a function";
|
err = "callback argument given to redict.register_function must be a function";
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
int lua_function_ref = luaL_ref(lua, LUA_REGISTRYINDEX);
|
int lua_function_ref = luaL_ref(lua, LUA_REGISTRYINDEX);
|
||||||
@ -289,7 +289,7 @@ static int luaRegisterFunctionReadNamedArgs(lua_State *lua, registerFunctionArgs
|
|||||||
continue; /* value was already popped, so no need to pop it out. */
|
continue; /* value was already popped, so no need to pop it out. */
|
||||||
} else if (!strcasecmp(key, "flags")) {
|
} else if (!strcasecmp(key, "flags")) {
|
||||||
if (!lua_istable(lua, -1)) {
|
if (!lua_istable(lua, -1)) {
|
||||||
err = "flags argument to redis.register_function must be a table representing function flags";
|
err = "flags argument to redict.register_function must be a table representing function flags";
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (luaRegisterFunctionReadFlags(lua, &flags) != C_OK) {
|
if (luaRegisterFunctionReadFlags(lua, &flags) != C_OK) {
|
||||||
@ -298,19 +298,19 @@ static int luaRegisterFunctionReadNamedArgs(lua_State *lua, registerFunctionArgs
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* unknown argument was given, raise an error */
|
/* unknown argument was given, raise an error */
|
||||||
err = "unknown argument given to redis.register_function";
|
err = "unknown argument given to redict.register_function";
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
lua_pop(lua, 1); /* pop the value to continue the iteration */
|
lua_pop(lua, 1); /* pop the value to continue the iteration */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!name) {
|
if (!name) {
|
||||||
err = "redis.register_function must get a function name argument";
|
err = "redict.register_function must get a function name argument";
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lua_f_ctx) {
|
if (!lua_f_ctx) {
|
||||||
err = "redis.register_function must get a callback argument";
|
err = "redict.register_function must get a callback argument";
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -335,12 +335,12 @@ static int luaRegisterFunctionReadPositionalArgs(lua_State *lua, registerFunctio
|
|||||||
sds desc = NULL;
|
sds desc = NULL;
|
||||||
luaFunctionCtx *lua_f_ctx = NULL;
|
luaFunctionCtx *lua_f_ctx = NULL;
|
||||||
if (!(name = luaGetStringSds(lua, 1))) {
|
if (!(name = luaGetStringSds(lua, 1))) {
|
||||||
err = "first argument to redis.register_function must be a string";
|
err = "first argument to redict.register_function must be a string";
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lua_isfunction(lua, 2)) {
|
if (!lua_isfunction(lua, 2)) {
|
||||||
err = "second argument to redis.register_function must be a function";
|
err = "second argument to redict.register_function must be a function";
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -363,7 +363,7 @@ error:
|
|||||||
static int luaRegisterFunctionReadArgs(lua_State *lua, registerFunctionArgs *register_f_args) {
|
static int luaRegisterFunctionReadArgs(lua_State *lua, registerFunctionArgs *register_f_args) {
|
||||||
int argc = lua_gettop(lua);
|
int argc = lua_gettop(lua);
|
||||||
if (argc < 1 || argc > 2) {
|
if (argc < 1 || argc > 2) {
|
||||||
luaPushError(lua, "wrong number of arguments to redis.register_function");
|
luaPushError(lua, "wrong number of arguments to redict.register_function");
|
||||||
return C_ERR;
|
return C_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -379,7 +379,7 @@ static int luaRegisterFunction(lua_State *lua) {
|
|||||||
|
|
||||||
loadCtx *load_ctx = luaGetFromRegistry(lua, REGISTRY_LOAD_CTX_NAME);
|
loadCtx *load_ctx = luaGetFromRegistry(lua, REGISTRY_LOAD_CTX_NAME);
|
||||||
if (!load_ctx) {
|
if (!load_ctx) {
|
||||||
luaPushError(lua, "redis.register_function can only be called on FUNCTION LOAD command");
|
luaPushError(lua, "redict.register_function can only be called on FUNCTION LOAD command");
|
||||||
return luaError(lua);
|
return luaError(lua);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1404,15 +1404,15 @@ void luaRegisterRedictAPI(lua_State* lua) {
|
|||||||
lua_pushcfunction(lua,luaRedictPcall);
|
lua_pushcfunction(lua,luaRedictPcall);
|
||||||
lua_setglobal(lua, "pcall");
|
lua_setglobal(lua, "pcall");
|
||||||
|
|
||||||
/* Register the redis commands table and fields */
|
/* Register the redict commands table and fields */
|
||||||
lua_newtable(lua);
|
lua_newtable(lua);
|
||||||
|
|
||||||
/* redis.call */
|
/* redict.call */
|
||||||
lua_pushstring(lua,"call");
|
lua_pushstring(lua,"call");
|
||||||
lua_pushcfunction(lua,luaRedictCallCommand);
|
lua_pushcfunction(lua,luaRedictCallCommand);
|
||||||
lua_settable(lua,-3);
|
lua_settable(lua,-3);
|
||||||
|
|
||||||
/* redis.pcall */
|
/* redict.pcall */
|
||||||
lua_pushstring(lua,"pcall");
|
lua_pushstring(lua,"pcall");
|
||||||
lua_pushcfunction(lua,luaRedictPCallCommand);
|
lua_pushcfunction(lua,luaRedictPCallCommand);
|
||||||
lua_settable(lua,-3);
|
lua_settable(lua,-3);
|
||||||
@ -1421,17 +1421,17 @@ void luaRegisterRedictAPI(lua_State* lua) {
|
|||||||
|
|
||||||
luaRegisterVersion(lua);
|
luaRegisterVersion(lua);
|
||||||
|
|
||||||
/* redis.setresp */
|
/* redict.setresp */
|
||||||
lua_pushstring(lua,"setresp");
|
lua_pushstring(lua,"setresp");
|
||||||
lua_pushcfunction(lua,luaSetResp);
|
lua_pushcfunction(lua,luaSetResp);
|
||||||
lua_settable(lua,-3);
|
lua_settable(lua,-3);
|
||||||
|
|
||||||
/* redis.sha1hex */
|
/* redict.sha1hex */
|
||||||
lua_pushstring(lua, "sha1hex");
|
lua_pushstring(lua, "sha1hex");
|
||||||
lua_pushcfunction(lua, luaRedictSha1hexCommand);
|
lua_pushcfunction(lua, luaRedictSha1hexCommand);
|
||||||
lua_settable(lua, -3);
|
lua_settable(lua, -3);
|
||||||
|
|
||||||
/* redis.error_reply and redis.status_reply */
|
/* redict.error_reply and redict.status_reply */
|
||||||
lua_pushstring(lua, "error_reply");
|
lua_pushstring(lua, "error_reply");
|
||||||
lua_pushcfunction(lua, luaRedictErrorReplyCommand);
|
lua_pushcfunction(lua, luaRedictErrorReplyCommand);
|
||||||
lua_settable(lua, -3);
|
lua_settable(lua, -3);
|
||||||
@ -1439,7 +1439,7 @@ void luaRegisterRedictAPI(lua_State* lua) {
|
|||||||
lua_pushcfunction(lua, luaRedictStatusReplyCommand);
|
lua_pushcfunction(lua, luaRedictStatusReplyCommand);
|
||||||
lua_settable(lua, -3);
|
lua_settable(lua, -3);
|
||||||
|
|
||||||
/* redis.set_repl and associated flags. */
|
/* redict.set_repl and associated flags. */
|
||||||
lua_pushstring(lua,"set_repl");
|
lua_pushstring(lua,"set_repl");
|
||||||
lua_pushcfunction(lua,luaRedictSetReplCommand);
|
lua_pushcfunction(lua,luaRedictSetReplCommand);
|
||||||
lua_settable(lua,-3);
|
lua_settable(lua,-3);
|
||||||
@ -1464,7 +1464,7 @@ void luaRegisterRedictAPI(lua_State* lua) {
|
|||||||
lua_pushnumber(lua,PROPAGATE_AOF|PROPAGATE_REPL);
|
lua_pushnumber(lua,PROPAGATE_AOF|PROPAGATE_REPL);
|
||||||
lua_settable(lua,-3);
|
lua_settable(lua,-3);
|
||||||
|
|
||||||
/* redis.acl_check_cmd */
|
/* redict.acl_check_cmd */
|
||||||
lua_pushstring(lua,"acl_check_cmd");
|
lua_pushstring(lua,"acl_check_cmd");
|
||||||
lua_pushcfunction(lua,luaRedictAclCheckCmdPermissionsCommand);
|
lua_pushcfunction(lua,luaRedictAclCheckCmdPermissionsCommand);
|
||||||
lua_settable(lua,-3);
|
lua_settable(lua,-3);
|
||||||
|
@ -520,7 +520,7 @@ start_server {tags {"scripting"}} {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
} e
|
} e
|
||||||
assert_match {*second argument to redis.register_function must be a function*} $e
|
assert_match {*second argument to redict.register_function must be a function*} $e
|
||||||
assert_equal [r fcall f1 0] {2}
|
assert_equal [r fcall f1 0] {2}
|
||||||
assert_equal [r fcall f2 0] {3}
|
assert_equal [r fcall f2 0] {3}
|
||||||
}
|
}
|
||||||
@ -568,7 +568,7 @@ start_server {tags {"scripting"}} {
|
|||||||
}
|
}
|
||||||
} e
|
} e
|
||||||
set _ $e
|
set _ $e
|
||||||
} {*wrong number of arguments to redis.register_function*}
|
} {*wrong number of arguments to redict.register_function*}
|
||||||
|
|
||||||
test {LIBRARIES - test registration with only name} {
|
test {LIBRARIES - test registration with only name} {
|
||||||
catch {
|
catch {
|
||||||
@ -577,7 +577,7 @@ start_server {tags {"scripting"}} {
|
|||||||
}
|
}
|
||||||
} e
|
} e
|
||||||
set _ $e
|
set _ $e
|
||||||
} {*calling redis.register_function with a single argument is only applicable to Lua table*}
|
} {*calling redict.register_function with a single argument is only applicable to Lua table*}
|
||||||
|
|
||||||
test {LIBRARIES - test registration with to many arguments} {
|
test {LIBRARIES - test registration with to many arguments} {
|
||||||
catch {
|
catch {
|
||||||
@ -586,7 +586,7 @@ start_server {tags {"scripting"}} {
|
|||||||
}
|
}
|
||||||
} e
|
} e
|
||||||
set _ $e
|
set _ $e
|
||||||
} {*wrong number of arguments to redis.register_function*}
|
} {*wrong number of arguments to redict.register_function*}
|
||||||
|
|
||||||
test {LIBRARIES - test registration with no string name} {
|
test {LIBRARIES - test registration with no string name} {
|
||||||
catch {
|
catch {
|
||||||
@ -595,7 +595,7 @@ start_server {tags {"scripting"}} {
|
|||||||
}
|
}
|
||||||
} e
|
} e
|
||||||
set _ $e
|
set _ $e
|
||||||
} {*first argument to redis.register_function must be a string*}
|
} {*first argument to redict.register_function must be a string*}
|
||||||
|
|
||||||
test {LIBRARIES - test registration with wrong name format} {
|
test {LIBRARIES - test registration with wrong name format} {
|
||||||
catch {
|
catch {
|
||||||
@ -781,7 +781,7 @@ start_server {tags {"scripting"}} {
|
|||||||
}
|
}
|
||||||
} e
|
} e
|
||||||
set _ $e
|
set _ $e
|
||||||
} {*function_name argument given to redis.register_function must be a string*}
|
} {*function_name argument given to redict.register_function must be a string*}
|
||||||
|
|
||||||
test {LIBRARIES - named arguments, bad callback type} {
|
test {LIBRARIES - named arguments, bad callback type} {
|
||||||
catch {
|
catch {
|
||||||
@ -794,7 +794,7 @@ start_server {tags {"scripting"}} {
|
|||||||
}
|
}
|
||||||
} e
|
} e
|
||||||
set _ $e
|
set _ $e
|
||||||
} {*callback argument given to redis.register_function must be a function*}
|
} {*callback argument given to redict.register_function must be a function*}
|
||||||
|
|
||||||
test {LIBRARIES - named arguments, bad description} {
|
test {LIBRARIES - named arguments, bad description} {
|
||||||
catch {
|
catch {
|
||||||
@ -809,7 +809,7 @@ start_server {tags {"scripting"}} {
|
|||||||
}
|
}
|
||||||
} e
|
} e
|
||||||
set _ $e
|
set _ $e
|
||||||
} {*description argument given to redis.register_function must be a string*}
|
} {*description argument given to redict.register_function must be a string*}
|
||||||
|
|
||||||
test {LIBRARIES - named arguments, unknown argument} {
|
test {LIBRARIES - named arguments, unknown argument} {
|
||||||
catch {
|
catch {
|
||||||
@ -825,7 +825,7 @@ start_server {tags {"scripting"}} {
|
|||||||
}
|
}
|
||||||
} e
|
} e
|
||||||
set _ $e
|
set _ $e
|
||||||
} {*unknown argument given to redis.register_function*}
|
} {*unknown argument given to redict.register_function*}
|
||||||
|
|
||||||
test {LIBRARIES - named arguments, missing function name} {
|
test {LIBRARIES - named arguments, missing function name} {
|
||||||
catch {
|
catch {
|
||||||
@ -839,7 +839,7 @@ start_server {tags {"scripting"}} {
|
|||||||
}
|
}
|
||||||
} e
|
} e
|
||||||
set _ $e
|
set _ $e
|
||||||
} {*redis.register_function must get a function name argument*}
|
} {*redict.register_function must get a function name argument*}
|
||||||
|
|
||||||
test {LIBRARIES - named arguments, missing callback} {
|
test {LIBRARIES - named arguments, missing callback} {
|
||||||
catch {
|
catch {
|
||||||
@ -851,7 +851,7 @@ start_server {tags {"scripting"}} {
|
|||||||
}
|
}
|
||||||
} e
|
} e
|
||||||
set _ $e
|
set _ $e
|
||||||
} {*redis.register_function must get a callback argument*}
|
} {*redict.register_function must get a callback argument*}
|
||||||
|
|
||||||
test {FUNCTION - test function restore with function name collision} {
|
test {FUNCTION - test function restore with function name collision} {
|
||||||
r function flush
|
r function flush
|
||||||
@ -1013,7 +1013,7 @@ start_server {tags {"scripting"}} {
|
|||||||
}
|
}
|
||||||
}} e
|
}} e
|
||||||
set _ $e
|
set _ $e
|
||||||
} {*flags argument to redis.register_function must be a table representing function flags*}
|
} {*flags argument to redict.register_function must be a table representing function flags*}
|
||||||
|
|
||||||
test {FUNCTION - wrong flag type} {
|
test {FUNCTION - wrong flag type} {
|
||||||
catch {r function load replace {#!lua name=test
|
catch {r function load replace {#!lua name=test
|
||||||
|
Loading…
Reference in New Issue
Block a user