You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by GitBox <gi...@apache.org> on 2020/12/14 09:35:23 UTC

[GitHub] [incubator-brpc] guodongxiaren opened a new issue #1305: 使用Redis Channel的时候发送Redis命令的疑问

guodongxiaren opened a new issue #1305:
URL: https://github.com/apache/incubator-brpc/issues/1305


   **Describe the bug (描述bug)**
   发现发送MGET的时候,用
   ```
   request->AddCommand("MGET %s", keys.c_str());
   ```
   keys是空格分隔的字符串。包含多个key。
   
   得到了reply总是异常。换成
   ```
   AddCommandByComponents(parts.data(), parts.size()); 
   //parts是vector<butil::StringPiece>的数组
   ```
   可以。解析逻辑相同。
   
   而使用ZRANGE的时候则相反,AddCommandByComponents传入butil::StringPiece凑成`ZRANGE key 0 -1`会得不到结果,
   ```
   int start = 0;
   int stop = -1;
   ...
   
   butil::StringPiece parts[4];
   parts[0].set("ZRANGE");
   parts[1].set(key.c_str());
   parts[2].set(std::to_string(start).c_str());
   parts[3].set(std::to_string(stop).c_str());
   request->AddCommandByComponents(&parts[0], 4);
   ```
   可以。
   
   而
   ```
   request->AddCommand("ZRANGE %s 0 -1", key.c_str());
   ```
   可以。解析逻辑相同。
   
   
   **To Reproduce (复现方法)**
   
   
   **Expected behavior (期望行为)**
   
   
   **Versions (各种版本)**
   OS:
   Compiler:
   brpc:
   protobuf:
   
   **Additional context/screenshots (更多上下文/截图)**
   
   


----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] cooper-zhzhang removed a comment on issue #1305: 使用Redis Channel的时候发送Redis命令的疑问

Posted by GitBox <gi...@apache.org>.
cooper-zhzhang removed a comment on issue #1305:
URL: https://github.com/apache/incubator-brpc/issues/1305#issuecomment-747277849


   请问你说的得到了reply总是异常 提示的是什么样的异常 能否截图呢


----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] cooper-zhzhang commented on issue #1305: 使用Redis Channel的时候发送Redis命令的疑问

Posted by GitBox <gi...@apache.org>.
cooper-zhzhang commented on issue #1305:
URL: https://github.com/apache/incubator-brpc/issues/1305#issuecomment-747277849


   请问你说的得到了reply总是异常 提示的是什么样的异常 能否截图呢


----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] cooper-zhzhang commented on issue #1305: 使用Redis Channel的时候发送Redis命令的疑问

Posted by GitBox <gi...@apache.org>.
cooper-zhzhang commented on issue #1305:
URL: https://github.com/apache/incubator-brpc/issues/1305#issuecomment-747435761


   
   `request->AddCommand(std::string("MGET ") + "my_key_2 my_key_1");`
   这样也是可以地
   


----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] zyearn commented on issue #1305: 使用Redis Channel的时候发送Redis命令的疑问

Posted by GitBox <gi...@apache.org>.
zyearn commented on issue #1305:
URL: https://github.com/apache/incubator-brpc/issues/1305#issuecomment-747737645


   > 而使用ZRANGE的时候则相反,AddCommandByComponents传入butil::StringPiece凑成ZRANGE key 0 -1会得不到结果,
   
   用StringPiece的时候需要原始的string是存在的,而这里StringPiece的参数是临时构造的string,在用parts的时候临时的string已经析构了。


----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] cooper-zhzhang commented on issue #1305: 使用Redis Channel的时候发送Redis命令的疑问

Posted by GitBox <gi...@apache.org>.
cooper-zhzhang commented on issue #1305:
URL: https://github.com/apache/incubator-brpc/issues/1305#issuecomment-747419590


   `request->AddCommand("MGET %s", keys.c_str());`
   之所以错误这个和redis的序列化有关系
   
   一个简单的例子
   `set my_key 1`
   序列化后为 `$3set\r\n$6my_key\r\n$11\r\n`
   表示客户端给服务器发送三个字符串(使用`\r\n`分割) 第一个是命令 其余两个是命令的参数
   服务器收到后理解为 set 命令后面跟两个参数  一个参数是my_key一个参数是1
   
   `std::string keys = "my_key_2 my_key_1";
   request->AddCommand("MGET %s", keys.c_str());`
   这个在序列化的时候直接使用keys.c_str() 替换了%s 
   所以序列化后为 `$4\r\nmget\r\n$17\r\nmy_key_2 my_key_1\r\n`
   服务器认为收到两个字符串
   第一个是`mget` 第二个是`my_key_2 my_key_1`
   即 mget 命令跟一个参数 参数为`my_key_2 my_key_1`注意参数中的空格,
   服务器认为你要找key为`my_key_2 my_key_1`的键值对
   
   正确的用法为 `request->AddCommand("MGET %s %s", "my_key_2", "my_key_1")`
   
   
   


----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] cooper-zhzhang removed a comment on issue #1305: 使用Redis Channel的时候发送Redis命令的疑问

Posted by GitBox <gi...@apache.org>.
cooper-zhzhang removed a comment on issue #1305:
URL: https://github.com/apache/incubator-brpc/issues/1305#issuecomment-747435761


   
   `request->AddCommand(std::string("MGET ") + "my_key_2 my_key_1");`
   这样也是可以地
   


----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] cooper-zhzhang edited a comment on issue #1305: 使用Redis Channel的时候发送Redis命令的疑问

Posted by GitBox <gi...@apache.org>.
cooper-zhzhang edited a comment on issue #1305:
URL: https://github.com/apache/incubator-brpc/issues/1305#issuecomment-747419590


   `request->AddCommand("MGET %s", keys.c_str());`
   之所以错误这个和redis的序列化有关系
   
   一个简单的例子
   `set my_key 1`
   序列化后为 `$3set\r\n$6my_key\r\n$11\r\n`
   表示客户端给服务器发送三个字符串(使用`\r\n`分割) 第一个是命令 其余两个是命令的参数
   服务器收到后理解为 set 命令后面跟两个参数  一个参数是my_key一个参数是1
   
   `std::string keys = "my_key_2 my_key_1";
   request->AddCommand("MGET %s", keys.c_str());`
   这个在序列化的时候直接使用keys.c_str() 替换了%s 
   所以序列化后为 `$4\r\nmget\r\n$17\r\nmy_key_2 my_key_1\r\n`
   服务器认为收到两个字符串
   第一个是`mget` 第二个是`my_key_2 my_key_1`
   即 mget 命令跟一个参数 参数为`my_key_2 my_key_1`注意参数中的空格,
   服务器认为你要找key为`my_key_2 my_key_1`的键值对
   
   正确的用法为 `request->AddCommand("MGET %s %s", "my_key_2", "my_key_1")`
   或者
   `request->AddCommand(std::string("MGET ") + "my_key_2 my_key_1");`
   


----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org