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
dad38c19
Commit
dad38c19
authored
Sep 16, 2019
by
antirez
Browse files
RESP3: report set/map as nested tables to Lua.
parent
888efc1b
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/scripting.c
View file @
dad38c19
...
@@ -202,9 +202,13 @@ char *redisProtocolToLuaType_Aggregate(lua_State *lua, char *reply, int atype) {
...
@@ -202,9 +202,13 @@ char *redisProtocolToLuaType_Aggregate(lua_State *lua, char *reply, int atype) {
}
}
}
else
if
(
server
.
lua_client
->
resp
==
3
)
{
}
else
if
(
server
.
lua_client
->
resp
==
3
)
{
/* Here we handle only Set and Map replies in RESP3 mode, since arrays
/* Here we handle only Set and Map replies in RESP3 mode, since arrays
* follow the above RESP2 code path. */
* follow the above RESP2 code path. Note that those are represented
* as a table with the "map" or "set" field populated with the actual
* table representing the set or the map type. */
p
+=
2
;
p
+=
2
;
lua_newtable
(
lua
);
lua_newtable
(
lua
);
lua_pushstring
(
lua
,
atype
==
'%'
?
"map"
:
"set"
);
lua_newtable
(
lua
);
for
(
j
=
0
;
j
<
mbulklen
;
j
++
)
{
for
(
j
=
0
;
j
<
mbulklen
;
j
++
)
{
p
=
redisProtocolToLuaType
(
lua
,
p
);
p
=
redisProtocolToLuaType
(
lua
,
p
);
if
(
atype
==
'%'
)
{
if
(
atype
==
'%'
)
{
...
@@ -214,6 +218,7 @@ char *redisProtocolToLuaType_Aggregate(lua_State *lua, char *reply, int atype) {
...
@@ -214,6 +218,7 @@ char *redisProtocolToLuaType_Aggregate(lua_State *lua, char *reply, int atype) {
}
}
lua_settable
(
lua
,
-
3
);
lua_settable
(
lua
,
-
3
);
}
}
lua_settable
(
lua
,
-
3
);
}
}
return
p
;
return
p
;
}
}
...
@@ -310,6 +315,8 @@ void luaReplyToRedisReply(client *c, lua_State *lua) {
...
@@ -310,6 +315,8 @@ void luaReplyToRedisReply(client *c, lua_State *lua) {
* Error are returned as a single element table with 'err' field.
* Error are returned as a single element table with 'err' field.
* Status replies are returned as single element table with 'ok'
* Status replies are returned as single element table with 'ok'
* field. */
* field. */
/* Handle error reply. */
lua_pushstring
(
lua
,
"err"
);
lua_pushstring
(
lua
,
"err"
);
lua_gettable
(
lua
,
-
2
);
lua_gettable
(
lua
,
-
2
);
t
=
lua_type
(
lua
,
-
1
);
t
=
lua_type
(
lua
,
-
1
);
...
@@ -321,8 +328,9 @@ void luaReplyToRedisReply(client *c, lua_State *lua) {
...
@@ -321,8 +328,9 @@ void luaReplyToRedisReply(client *c, lua_State *lua) {
lua_pop
(
lua
,
2
);
lua_pop
(
lua
,
2
);
return
;
return
;
}
}
lua_pop
(
lua
,
1
);
/* Discard field name pushed before. */
lua_pop
(
lua
,
1
);
/* Handle status reply. */
lua_pushstring
(
lua
,
"ok"
);
lua_pushstring
(
lua
,
"ok"
);
lua_gettable
(
lua
,
-
2
);
lua_gettable
(
lua
,
-
2
);
t
=
lua_type
(
lua
,
-
1
);
t
=
lua_type
(
lua
,
-
1
);
...
@@ -332,24 +340,25 @@ void luaReplyToRedisReply(client *c, lua_State *lua) {
...
@@ -332,24 +340,25 @@ void luaReplyToRedisReply(client *c, lua_State *lua) {
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
,
1
);
}
else
{
return
;
void
*
replylen
=
addReplyDeferredLen
(
c
);
}
int
j
=
1
,
mbulklen
=
0
;
lua_pop
(
lua
,
1
);
/* Discard field name pushed before. */
lua_pop
(
lua
,
1
);
/* Discard the 'ok' field value we popped */
/* Handle the array reply. */
while
(
1
)
{
void
*
replylen
=
addReplyDeferredLen
(
c
);
lua_pushnumber
(
lua
,
j
++
);
int
j
=
1
,
mbulklen
=
0
;
lua_gettable
(
lua
,
-
2
);
while
(
1
)
{
t
=
lua_type
(
lua
,
-
1
);
lua_pushnumber
(
lua
,
j
++
);
if
(
t
==
LUA_TNIL
)
{
lua_gettable
(
lua
,
-
2
);
lua_pop
(
lua
,
1
);
t
=
lua_type
(
lua
,
-
1
);
break
;
if
(
t
==
LUA_TNIL
)
{
}
lua_pop
(
lua
,
1
);
luaReplyToRedisReply
(
c
,
lua
);
break
;
mbulklen
++
;
}
}
setDeferredArrayLen
(
c
,
replylen
,
mbulklen
);
luaReplyToRedisReply
(
c
,
lua
);
mbulklen
++
;
}
}
setDeferredArrayLen
(
c
,
replylen
,
mbulklen
);
break
;
break
;
default:
default:
addReplyNull
(
c
);
addReplyNull
(
c
);
...
...
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