lihongjie0209 / myblog

4 stars 0 forks source link

Redis: pipeline #75

Open lihongjie0209 opened 4 years ago

lihongjie0209 commented 4 years ago

Redis指令执行的流程

Redis is a TCP server using the client-server model and what is called a Request/Response protocol.

This means that usually a request is accomplished with the following steps:

  1. The client sends a query to the server, and reads from the socket, usually in a blocking way, for the server response.
  2. The server processes the command and sends the response back to the client.
lihongjie0209 commented 4 years ago

使用流水线避免等待

A Request/Response server can be implemented so that it is able to process new requests even if the client didn't already read the old responses. This way it is possible to send multiple commands to the server without waiting for the replies at all, and finally read the replies in a single step.

This is called pipelining, and is a technique widely in use since many decades. For instance many POP3 protocol implementations already supported this feature, dramatically speeding up the process of downloading new emails from the server.

第一个请求发出之后没必要等待响应就发送第二个请求, 所有请求发出之后再等待响应.