You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kvrocks.apache.org by "enjoy-binbin (via GitHub)" <gi...@apache.org> on 2024/03/01 04:49:53 UTC

Re: [PR] Add support of lua function 'redis.resp()' [kvrocks]

enjoy-binbin commented on code in PR #2130:
URL: https://github.com/apache/kvrocks/pull/2130#discussion_r1508477905


##########
src/storage/scripting.cc:
##########
@@ -848,6 +853,29 @@ int RedisReturnSingleFieldTable(lua_State *lua, const char *field) {
   return 1;
 }
 
+int RedisSetResp(lua_State *lua) {
+  auto srv = GetServer(lua);
+  auto conn = srv->GetCurrentConnection();
+  int argc = lua_gettop(lua);
+
+  if (argc != 1) {
+    PushError(lua, "redis.setresp() requires one argument.");
+    return 1;
+  }
+
+  int resp = static_cast<int>(lua_tonumber(lua, -1));
+  if (resp != 2 && resp != 3) {
+    PushError(lua, "RESP version must be 2 or 3.");
+    return 1;
+  }
+  conn->SetProtocolVersion(resp == 2 ? redis::RESP::v2 : redis::RESP::v3);
+  if (resp == 3 && !srv->GetConfig()->resp3_enabled) {
+    PushError(lua, "you need set resp_enabled to yes to enable RESP3.");

Review Comment:
   It looks like there is no way we can use resp2 and resp3 at the same time?
   For example, use resp2 for one lua and resp3 for another lua.
   
   ```suggestion
       PushError(lua, "You need set resp3-enabled to yes to enable RESP3.");
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org