Redis Pipeline Technology

Source: Internet
Author: User
Tags redis redis server

Redis is a CS-mode TCP server that uses a request-response protocol similar to HTTP. A client can initiate multiple request commands from a single socket connection. After each request command is issued, the client usually blocks and waits for the Redis service to process, and the result is returned to the client via a response message after Redis finishes processing the request. The basic communication process is as follows:

CLIENT:INCR x
server:1
client:incr x
server:2
client:incr x
server:3
client:incr x
Ser Ver:4

Basically four commands require 8 TCP messages to complete. Due to the network latency of the communication, the packet transfer time between the client and server takes 0.125 seconds. Then the above four commands 8 messages will take at least 1 seconds to complete. This way, even though Redis can handle 100 commands per second, our client can only issue four commands in a second. This shows that the processing power of Redis is not fully utilized. In addition to the ability to handle multiple key commands with a single command such as Mget,mset, we can also use pipeline to send out multiple commands from the client, without waiting for the response of a single command to return. The Redis server then processes multiple commands and packages the results of multiple commands back to the client. The communication process is as follows:

CLIENT:INCR x
client:incr x
client:incr x
client:incr x
server:1
server:2
server:3
 
  server:4
 

Assume that the TCP message is not split because it is too long. Possibly two TCP messages can complete four commands, the client can put four INCR command to send a TCP message together, the server can put the processing results of four commands to a TCP message return. By pipeline mode when there is a large amount of operation. We can save a lot of time originally wasted on network latency. Note that the pipeline Package command is sent, and Redis must cache all command processing results before all commands are processed. The more commands are packaged, the more memory is consumed by the cache. So the more you pack the more commands the better.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.