Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
c792504f
Commit
c792504f
authored
Sep 16, 2019
by
antirez
Browse files
RESP3: handle map Lua -> Redis conversion.
parent
dad38c19
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/scripting.c
View file @
c792504f
...
@@ -297,6 +297,8 @@ void luaSortArray(lua_State *lua) {
...
@@ -297,6 +297,8 @@ void luaSortArray(lua_State *lua) {
* Lua reply to Redis reply conversion functions.
* Lua reply to Redis reply conversion functions.
* ------------------------------------------------------------------------- */
* ------------------------------------------------------------------------- */
/* Reply to client 'c' converting the top element in the Lua stack to a
* Redis reply. As a side effect the element is consumed from the stack. */
void luaReplyToRedisReply(client *c, lua_State *lua) {
void luaReplyToRedisReply(client *c, lua_State *lua) {
int t = lua_type(lua,-1);
int t = lua_type(lua,-1);
...
@@ -339,7 +341,29 @@ void luaReplyToRedisReply(client *c, lua_State *lua) {
...
@@ -339,7 +341,29 @@ void luaReplyToRedisReply(client *c, lua_State *lua) {
sdsmapchars(ok,"\r\n"," ",2);
sdsmapchars(ok,"\r\n"," ",2);
addReplySds(c,sdscatprintf(sdsempty(),"+%s\r\n",ok));
addReplySds(c,sdscatprintf(sdsempty(),"+%s\r\n",ok));
sdsfree(ok);
sdsfree(ok);
lua_pop(lua,1);
lua_pop(lua,2);
return;
}
lua_pop(lua,1); /* Discard field name pushed before. */
/* Handle map reply. */
lua_pushstring(lua,"map");
lua_gettable(lua,-2);
t = lua_type(lua,-1);
if (t == LUA_TTABLE) {
int maplen = 0;
void *replylen = addReplyDeferredLen(c);
lua_pushnil(lua); /* Use nil to start iteration. */
while (lua_next(lua,-2)) {
/* Stack now: table, key, value */
luaReplyToRedisReply(c, lua); /* Return value. */
lua_pushvalue(lua,-1); /* Dup key before consuming. */
luaReplyToRedisReply(c, lua); /* Return key. */
/* Stack now: table, key. */
maplen++;
}
setDeferredMapLen(c,replylen,maplen);
lua_pop(lua,2);
return;
return;
}
}
lua_pop(lua,1); /* Discard field name pushed before. */
lua_pop(lua,1); /* Discard field name pushed before. */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment