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
93c52ff5
Commit
93c52ff5
authored
Sep 13, 2019
by
antirez
Browse files
RESP3: implement lua.setresp().
parent
b170a01f
Changes
1
Show whitespace changes
Inline
Side-by-side
src/scripting.c
View file @
93c52ff5
...
@@ -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
,
int
atype
);
char
*
redisProtocolToLuaType_
Aggregate
(
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,9 +132,9 @@ char *redisProtocolToLuaType(lua_State *lua, char* reply) {
...
@@ -132,9 +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
,
*
p
);
break
;
case
'*'
:
p
=
redisProtocolToLuaType_
Aggregate
(
lua
,
reply
,
*
p
);
break
;
case
'%'
:
p
=
redisProtocolToLuaType_
MultiBulk
(
lua
,
reply
,
*
p
);
break
;
case
'%'
:
p
=
redisProtocolToLuaType_
Aggregate
(
lua
,
reply
,
*
p
);
break
;
case
'~'
:
p
=
redisProtocolToLuaType_
MultiBulk
(
lua
,
reply
,
*
p
);
break
;
case
'~'
:
p
=
redisProtocolToLuaType_
Aggregate
(
lua
,
reply
,
*
p
);
break
;
}
}
return
p
;
return
p
;
}
}
...
@@ -182,7 +182,7 @@ char *redisProtocolToLuaType_Error(lua_State *lua, char *reply) {
...
@@ -182,7 +182,7 @@ char *redisProtocolToLuaType_Error(lua_State *lua, char *reply) {
return
p
+
2
;
return
p
+
2
;
}
}
char
*
redisProtocolToLuaType_
MultiBulk
(
lua_State
*
lua
,
char
*
reply
,
int
atype
)
{
char
*
redisProtocolToLuaType_
Aggregate
(
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
;
...
@@ -859,6 +859,25 @@ int luaLogCommand(lua_State *lua) {
...
@@ -859,6 +859,25 @@ int luaLogCommand(lua_State *lua) {
return
0
;
return
0
;
}
}
/* redis.setresp() */
int
luaSetResp
(
lua_State
*
lua
)
{
int
argc
=
lua_gettop
(
lua
);
if
(
argc
!=
1
)
{
lua_pushstring
(
lua
,
"redis.setresp() requires one argument."
);
return
lua_error
(
lua
);
}
int
resp
=
lua_tonumber
(
lua
,
-
argc
);
if
(
resp
!=
2
&&
resp
!=
3
)
{
lua_pushstring
(
lua
,
"RESP version must be 2 or 3."
);
return
lua_error
(
lua
);
}
server
.
lua_client
->
resp
=
resp
;
return
0
;
}
/* ---------------------------------------------------------------------------
/* ---------------------------------------------------------------------------
* Lua engine initialization and reset.
* Lua engine initialization and reset.
* ------------------------------------------------------------------------- */
* ------------------------------------------------------------------------- */
...
@@ -986,6 +1005,11 @@ void scriptingInit(int setup) {
...
@@ -986,6 +1005,11 @@ void scriptingInit(int setup) {
lua_pushcfunction
(
lua
,
luaLogCommand
);
lua_pushcfunction
(
lua
,
luaLogCommand
);
lua_settable
(
lua
,
-
3
);
lua_settable
(
lua
,
-
3
);
/* redis.setresp */
lua_pushstring
(
lua
,
"setresp"
);
lua_pushcfunction
(
lua
,
luaSetResp
);
lua_settable
(
lua
,
-
3
);
lua_pushstring
(
lua
,
"LOG_DEBUG"
);
lua_pushstring
(
lua
,
"LOG_DEBUG"
);
lua_pushnumber
(
lua
,
LL_DEBUG
);
lua_pushnumber
(
lua
,
LL_DEBUG
);
lua_settable
(
lua
,
-
3
);
lua_settable
(
lua
,
-
3
);
...
@@ -1379,8 +1403,9 @@ void evalGenericCommand(client *c, int evalsha) {
...
@@ -1379,8 +1403,9 @@ void evalGenericCommand(client *c, int evalsha) {
luaSetGlobalArray
(
lua
,
"KEYS"
,
c
->
argv
+
3
,
numkeys
);
luaSetGlobalArray
(
lua
,
"KEYS"
,
c
->
argv
+
3
,
numkeys
);
luaSetGlobalArray
(
lua
,
"ARGV"
,
c
->
argv
+
3
+
numkeys
,
c
->
argc
-
3
-
numkeys
);
luaSetGlobalArray
(
lua
,
"ARGV"
,
c
->
argv
+
3
+
numkeys
,
c
->
argc
-
3
-
numkeys
);
/* Se
lec
t the
right DB in the context of the Lua client
*/
/* Set the
Lua client database and protocol.
*/
selectDb
(
server
.
lua_client
,
c
->
db
->
id
);
selectDb
(
server
.
lua_client
,
c
->
db
->
id
);
server
.
lua_client
->
resp
=
2
;
/* Default is RESP2, scripts can change it. */
/* Set a hook in order to be able to stop the script execution if it
/* Set a hook in order to be able to stop the script execution if it
* is running for too much time.
* is running for too much time.
...
...
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