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
a1feda23
Commit
a1feda23
authored
Nov 26, 2018
by
antirez
Browse files
RESP3: Scripting RESP3 mode set/map protocol -> Lua conversion.
parent
9330bcc7
Changes
1
Show whitespace changes
Inline
Side-by-side
src/scripting.c
View file @
a1feda23
...
@@ -42,7 +42,7 @@ char *redisProtocolToLuaType_Int(lua_State *lua, char *reply);
...
@@ -42,7 +42,7 @@ char *redisProtocolToLuaType_Int(lua_State *lua, char *reply);
char *redisProtocolToLuaType_Bulk(lua_State *lua, char *reply);
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 *redisProtocolToLuaType_Error(lua_State *lua, char *reply);
char *redisProtocolToLuaType_Error(lua_State *lua, char *reply);
char
*
redisProtocolToLuaType_MultiBulk
(
lua_State
*
lua
,
char
*
reply
);
char *redisProtocolToLuaType_MultiBulk(lua_State *lua, char *reply
, int atype
);
int redis_math_random (lua_State *L);
int redis_math_random (lua_State *L);
int redis_math_randomseed (lua_State *L);
int redis_math_randomseed (lua_State *L);
void ldbInit(void);
void ldbInit(void);
...
@@ -132,7 +132,9 @@ char *redisProtocolToLuaType(lua_State *lua, char* reply) {
...
@@ -132,7 +132,9 @@ char *redisProtocolToLuaType(lua_State *lua, char* reply) {
case '$': p = redisProtocolToLuaType_Bulk(lua,reply); break;
case '$': p = redisProtocolToLuaType_Bulk(lua,reply); break;
case '+': p = redisProtocolToLuaType_Status(lua,reply); break;
case '+': p = redisProtocolToLuaType_Status(lua,reply); break;
case '-': p = redisProtocolToLuaType_Error(lua,reply); break;
case '-': p = redisProtocolToLuaType_Error(lua,reply); break;
case
'*'
:
p
=
redisProtocolToLuaType_MultiBulk
(
lua
,
reply
);
break
;
case '*': p = redisProtocolToLuaType_MultiBulk(lua,reply,*p); break;
case '%': p = redisProtocolToLuaType_MultiBulk(lua,reply,*p); break;
case '~': p = redisProtocolToLuaType_MultiBulk(lua,reply,*p); break;
}
}
return p;
return p;
}
}
...
@@ -180,12 +182,13 @@ char *redisProtocolToLuaType_Error(lua_State *lua, char *reply) {
...
@@ -180,12 +182,13 @@ char *redisProtocolToLuaType_Error(lua_State *lua, char *reply) {
return p+2;
return p+2;
}
}
char
*
redisProtocolToLuaType_MultiBulk
(
lua_State
*
lua
,
char
*
reply
)
{
char *redisProtocolToLuaType_MultiBulk(lua_State *lua, char *reply
, int atype
) {
char *p = strchr(reply+1,'\r');
char *p = strchr(reply+1,'\r');
long long mbulklen;
long long mbulklen;
int j = 0;
int j = 0;
string2ll(reply+1,p-reply-1,&mbulklen);
string2ll(reply+1,p-reply-1,&mbulklen);
if (server.lua_caller->resp == 2 || atype == '*') {
p += 2;
p += 2;
if (mbulklen == -1) {
if (mbulklen == -1) {
lua_pushboolean(lua,0);
lua_pushboolean(lua,0);
...
@@ -197,6 +200,21 @@ char *redisProtocolToLuaType_MultiBulk(lua_State *lua, char *reply) {
...
@@ -197,6 +200,21 @@ char *redisProtocolToLuaType_MultiBulk(lua_State *lua, char *reply) {
p = redisProtocolToLuaType(lua,p);
p = redisProtocolToLuaType(lua,p);
lua_settable(lua,-3);
lua_settable(lua,-3);
}
}
} else if (server.lua_caller->resp == 3) {
/* Here we handle only Set and Map replies in RESP3 mode, since arrays
* follow the above RESP2 code path. */
p += 2;
lua_newtable(lua);
for (j = 0; j < mbulklen; j++) {
p = redisProtocolToLuaType(lua,p);
if (atype == '%') {
p = redisProtocolToLuaType(lua,p);
} else {
lua_pushboolean(lua,1);
}
lua_settable(lua,-3);
}
}
return p;
return p;
}
}
...
...
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