Redis pipeline technology

Source: Internet
Author: User
 

Redis is a TCP Service Based on the client-server model and request/response protocol. This means that the next request usually follows the following steps:

  • The client sends a query request to the server and listens to the socket to return the query request, usually in blocking mode, waiting for the server to respond.
  • The server processes the command and returns the result to the client.
Redis pipeline technology

The redis pipeline technology allows the client to continue sending requests to the server when the server does not respond, and finally read the responses of all servers at one time.

Instance

To view the redis pipeline, you only need to start the redis instance and enter the following command:

$(echo -en "PING\r\n SET runoobkey redis\r\nGET runoobkey\r\nINCR visitor\r\nINCR visitor\r\nINCR visitor\r\n"; sleep 10) | nc localhost 6379+PONG+OKredis:1:2:3

In the above example, we usePingCommand to check whether the redis service is available. Then we set the value of runoobkey to redis. Then we get the value of runoobkey and increase the value of visitor three times.

In the returned results, we can see that these commands are submitted to the redis service at one time, and finally read the responses of all servers at one time.

Advantages of pipeline technology

The most significant advantage of pipeline technology is to improve the performance of redis services.

Some Test Data

In the following test, we will use the redis Ruby client to support pipeline technical features and test the pipeline technology's speed improvement effect.

require ‘rubygems‘ require ‘redis‘def bench(descr) start = Time.now yield puts "#{descr} #{Time.now-start} seconds" enddef without_pipelining r = Redis.new 10000.times {     r.ping } enddef with_pipelining r = Redis.new r.pipelined {     10000.times {         r.ping     } } endbench("without pipelining") {     without_pipelining } bench("with pipelining") {     with_pipelining }

The data from executing the above simple script on Mac OS X in the LAN indicates that the round-trip latency has been greatly improved after the pipeline operation is enabled.

without pipelining 1.185238 seconds with pipelining 0.250783 seconds

As you can see, after opening the pipeline, our speed has increased by 5 times.

Redis pipeline technology

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.