当 Redis 中有 1 个以上的命令时,我应该总是使用流水线吗? [英] Should I always use pipelining when there are more than 1 command in Redis?

查看:51
本文介绍了当 Redis 中有 1 个以上的命令时,我应该总是使用流水线吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 redis 新手,有点困惑什么时候应该使用流水线,还是应该在有 1 个以上的命令要发送时一直使用它?

I am new to redis, and a little bit confused when I should use pipelining or should I use it all the time when there are more than 1 command to be sent?

例如,如果我想一次发送 10 个 SET 命令到 redis 服务器,我是应该简单地一个一个运行这 10 个命令还是应该将它们流水线化?

For example, 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 个 SET 命令而不是一个一个地发送它们有什么缺点吗?

Are there any disadvantage to pipeline 10 SET commands instead of sending them one by one?

非常感谢.

推荐答案

什么时候应该使用流水线

when I should use pipelining

Pipeline 用于减少 RTT,以便在需要向 Redis 发送大量命令时提高性能.

Pipeline is used to reduce RTT, so that you can improve the performance, when you need to send many commands to Redis.

当要发送的命令超过 1 个时,我应该一直使用它吗?

should I use it all the time when there are more than 1 command to be sent?

这取决于.你应该逐案讨论.

It depends. You should discuss it case by case.

如果我想一次发送 10 个 SET 命令到 redis 服务器,我应该简单地一个一个运行这 10 个命令还是我应该将它们流水线化?

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

Pipline these commands will be much faster than sending 10 commands. However, in this particular case, the best choice is using the MSET command.

管道 10 个 SET 命令而不是一个一个地发送它们有什么缺点吗?

Are there any disadvantage to pipeline 10 SET commands instead of sending them one by one?

使用管道,Redis 需要消耗更多内存来保存所有这些管道命令的结果,直到您获取这些结果.因此,如果您通过管道传输太多命令,那可能是个问题.

With pipeline, Redis needs to consume more memory to hold the result of all these piped commands until you fetch these result. So if you pipe too many commands, that's might be a problem.

这篇关于当 Redis 中有 1 个以上的命令时,我应该总是使用流水线吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆