【发布时间】:2016-01-21 04:59:48
【问题描述】:
我想了解,redis 中的管道衬里如何工作?根据我阅读的一篇博客,对于此代码
Pipeline pipeline = jedis.pipelined();
long start = System.currentTimeMillis();
for (int i = 0; i < 100000; i++) {
pipeline.set("" + i, "" + i);
}
List<Object> results = pipeline.execute();
Every call to pipeline.set() effectively sends the SET command to Redis (you can easily see this by setting a breakpoint inside the loop and querying Redis with redis-cli). The call to pipeline.execute() is when the reading of all the pending responses happens.
所以基本上,当我们使用流水线时,当我们执行上面设置的任何命令时,该命令会在服务器上执行,但在我们执行 pipeline.execute() 之前我们不会收集响应。
但是,根据 pyredis 的文档,
Pipelines are a subclass of the base Redis class that provide support for buffering multiple commands to the server in a single request.
我认为,这意味着,我们使用流水线,当我们执行 pipe.execute() 时,所有命令都被缓冲并发送到服务器,因此这种行为与上述行为不同。
谁能告诉我使用 pyreids 时的正确行为是什么?
【问题讨论】:
标签: redis