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
0d916763
Commit
0d916763
authored
May 02, 2011
by
antirez
Browse files
Status replies converted in a special way like errors in the Lua <-> Redis conversion code.
parent
e8092bf6
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/scripting.c
View file @
0d916763
...
@@ -79,7 +79,10 @@ char *redisProtocolToLuaType_Bulk(lua_State *lua, char *reply) {
...
@@ -79,7 +79,10 @@ char *redisProtocolToLuaType_Bulk(lua_State *lua, char *reply) {
char
*
redisProtocolToLuaType_Status
(
lua_State
*
lua
,
char
*
reply
)
{
char
*
redisProtocolToLuaType_Status
(
lua_State
*
lua
,
char
*
reply
)
{
char
*
p
=
strchr
(
reply
+
1
,
'\r'
);
char
*
p
=
strchr
(
reply
+
1
,
'\r'
);
lua_newtable
(
lua
);
lua_pushstring
(
lua
,
"ok"
);
lua_pushlstring
(
lua
,
reply
+
1
,
p
-
reply
-
1
);
lua_pushlstring
(
lua
,
reply
+
1
,
p
-
reply
-
1
);
lua_settable
(
lua
,
-
3
);
return
p
+
2
;
return
p
+
2
;
}
}
...
@@ -246,20 +249,32 @@ void luaReplyToRedisReply(redisClient *c, lua_State *lua) {
...
@@ -246,20 +249,32 @@ void luaReplyToRedisReply(redisClient *c, lua_State *lua) {
addReplyLongLong
(
c
,(
long
long
)
lua_tonumber
(
lua
,
1
));
addReplyLongLong
(
c
,(
long
long
)
lua_tonumber
(
lua
,
1
));
break
;
break
;
case
LUA_TTABLE
:
case
LUA_TTABLE
:
/* We need to check if it is an array or an error.
/* We need to check if it is an array, an error, or a status reply.
* 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 elment table with 'ok' field */
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
);
if
(
t
==
LUA_TSTRING
)
{
if
(
t
==
LUA_TSTRING
)
{
addReplySds
(
c
,
sdscatprintf
(
sdsempty
(),
addReplySds
(
c
,
sdscatprintf
(
sdsempty
(),
"-%s
\r\n
"
,(
char
*
)
lua_tostring
(
lua
,
-
1
)));
"-%s
\r\n
"
,(
char
*
)
lua_tostring
(
lua
,
-
1
)));
lua_pop
(
lua
,
2
);
return
;
}
lua_pop
(
lua
,
1
);
lua_pushstring
(
lua
,
"ok"
);
lua_gettable
(
lua
,
-
2
);
t
=
lua_type
(
lua
,
-
1
);
if
(
t
==
LUA_TSTRING
)
{
addReplySds
(
c
,
sdscatprintf
(
sdsempty
(),
"+%s
\r\n
"
,(
char
*
)
lua_tostring
(
lua
,
-
1
)));
lua_pop
(
lua
,
1
);
lua_pop
(
lua
,
1
);
}
else
{
}
else
{
void
*
replylen
=
addDeferredMultiBulkLength
(
c
);
void
*
replylen
=
addDeferredMultiBulkLength
(
c
);
int
j
=
1
,
mbulklen
=
0
;
int
j
=
1
,
mbulklen
=
0
;
lua_pop
(
lua
,
1
);
/* Discard the '
err
' field value we popped */
lua_pop
(
lua
,
1
);
/* Discard the '
ok
' field value we popped */
while
(
1
)
{
while
(
1
)
{
lua_pushnumber
(
lua
,
j
++
);
lua_pushnumber
(
lua
,
j
++
);
lua_gettable
(
lua
,
-
2
);
lua_gettable
(
lua
,
-
2
);
...
...
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