如何在Redis中执行命令而完全没有任何响应? [英] How can I execute commands in redis without getting any response at all?
问题描述
我尝试在Redis上执行命令,但不关心任何响应,甚至不希望使网络流量最小化.一位Lua说 answer 不返回任何内容的脚本可以帮助实现这一目标,但是当我在redis-cli上尝试并嗅探我的包时,无论我是否返回一个脚本或不返回任何脚本,我仍然会在客户端和服务器之间传输相同数量的包.返回整数1.
I try to execute commands on redis but don't care for any response and don't even want any to minimize network traffic. One answer on stackoverflow said a Lua scripts that doesn't return anything could help to achieve that, but when I try it on the redis-cli and sniff my packages I still get the same number of packages transfered between client and server whether I have a script returning nothing or one that returns Integer 1.
示例查询为:
- EVAL" 0
- EVAL返回1" 0
在两种情况下,wireshark都显示了4个交换的软件包.一个[PSH,ACK]客户端到服务器,[ACK]从服务器到客户端,[PSH,ACK]从服务器到客户端,[ACK]从客户端回到服务器. 在第一种情况下,我期望redis响应的[PSH,ACK]程序包包含以下数据:
In both cases wireshark shows 4 packages exchanged. One [PSH, ACK] client to server, [ACK] from the server to the client, [PSH, ACK] from the server to the client and [ACK] back from the client to the server. In the first case the [PSH, ACK] package that I expect to be the response from redis contains the following data:
0000 02 00 00 00 45 00 00 39 bc a8 40 00 40 06 00 00 ....E..9 ..@.@...
0010 7f 00 00 01 7f 00 00 01 18 eb e6 bb 03 4d 7c 9c ........ .....M|.
0020 e2 97 bf 53 80 18 23 df fe 2d 00 00 01 01 08 0a ...S..#. .-......
0030 11 cd c0 31 11 cd c0 31 24 2d 31 0d 0a ...1...1 $-1..
在第二种情况下,此软件包包含:
In the second case this package contains:
0000 02 00 00 00 45 00 00 38 fa 9f 40 00 40 06 00 00 ....E..8 ..@.@...
0010 7f 00 00 01 7f 00 00 01 18 eb e6 bb 03 4d 7c a1 ........ .....M|.
0020 e2 97 bf 76 80 18 23 dd fe 2c 00 00 01 01 08 0a ...v..#. .,......
0030 11 ce be 46 11 ce be 46 3a 31 0d 0a ...F...F :1..
对于第二种情况,要点很明确. :1是1的整数回复.但是对于第一种情况,我不确定. $是批量答复的指示器,-是错误的指示器.这是否意味着$ -1是redis-cli中显示的(nil)数据? 还是我在那里完全错了?如果我是对的,是否有可能告诉redis我根本不需要任何响应(命令的ACK除外)?还是我需要拨出redis代码并自己实现?
For the second case the point is clear. :1 is the integer reply for 1. But for the first case I'm not sure. $ is the indicator for bulk reply and - the indicator for error. Does this mean that $-1 is the data for the (nil) that is shown in the redis-cli? Or am I completely wrong there? And if I am right, is there a possibility to tell redis that I don't want any response at all (except the ACK for the command)? Or would I have to fork the redis code and implement this myself?
我非常感谢在不深入研究Redis源代码的情况下如何实现完全不响应的任何提示.
I really appreciate any hints on how to achieve getting no response at all without digging into the redis source code.
推荐答案
EVAL "" 0 returns $-1\r\n
EVAL "return 1" 0 returns :1\r\n
在第一种情况下,$ -1是用于表示nil值的特定批量答复(如
In the first case, $-1 is a specific bulk-reply to be used to represent the nil value (as described in the protocol specification)
AFAIK,无法告诉Redis不必发送答复(即使是空答案).
AFAIK, there is no possibility to tell Redis it does not have to send a reply (even for an empty answer).
正如Marc Gravell所解释的那样,您可以使用Lua捆绑多个操作并减少答复数据量.但是,您将避免避免最少的回复数据包.
As explained by Marc Gravell, you can use Lua to bundle several operations and reduce the volume of the reply data. However, you will not avoid the minimal reply packet.
例如,您可以在一个Lua脚本中运行100个操作,并有一个最小的数据包作为答复.但是,除非更改Redis源代码,否则无法避免IMO使用此数据包.
For instance you could run 100 operations in one Lua script and have one single minimal packet as a reply. However, this packet cannot be avoided IMO, except by altering Redis source code.
这篇关于如何在Redis中执行命令而完全没有任何响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!