我是 Redis 的新手,当要发送超过 1 个命令时我应该使用流水线还是应该一直使用流水线有点困惑?
例如,如果我想一次向 Redis 服务器发送 10 个 SET 命令,我应该简单地一个接一个地运行这 10 个命令,还是应该管道化它们?
通过管道传输 10 个 SET 命令而不是一个一个地发送它们有什么缺点吗?
最佳答案
when I should use pipelining
管道用于减少 RTT,以便在需要向 Redis 发送大量命令时提高性能。
should I use it all the time when there are more than 1 command to be sent?
这取决于。您应该逐案讨论。
if I want to send 10 SET commands to redis server at a time, should I simply run the 10 commands one by one or should I pipeline them?
传递这些命令比发送 10 个命令要快得多。但是,在这种特殊情况下,最好的选择是使用 MSET
命令。
Are there any disadvantage to pipeline 10 SET commands instead of sending them one by one?
有了管道,Redis 需要消耗更多的内存来保存所有这些管道命令的结果,然后再将它们发送给客户端。因此,如果您通过管道传递太多命令,那可能会成为一个问题。
关于redis - 当 Redis 中有超过 1 个命令时,我是否应该始终使用流水线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54900928/