我想了解,redis中的管道襯裏是如何工作的?根據一個博客我看了,對於這個代碼redis管道在pyredis中如何工作?
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時什麼是正確的行爲?