Redis Pipeline Technology

Source: Internet
Author: User

Redis is a TCP service based on a client-server model and a request/response protocol. This means that typically a request follows these steps:

    • The client sends a query request to the server and listens for the socket return, usually in blocking mode, waiting for the service side to respond.
    • The server handles the command and returns the result to the client.
Redis Pipeline Technology

Redis pipeline technology can continue to send requests to the server when the service side is not responding, and eventually read all server-side responses at once.

Instance

To view the Redis pipeline, just start the Redis instance and enter the following command:

  1. $(echo -en "ping\r\n SET w3ckey redis\r\nget w3ckey\r\nincr visitor\r\nincr visitor\r\nincr Visitor \ r \ n "; sleep ) | nc localhost 6379
  2. +PONG
  3. +OK
  4. Redis
  5. :1
  6. :2
  7. :3

In the above example we see if the Redis service is available by using the PING command, after which we set the W3ckey value to Redis, then we get the value of W3ckey and make the visitor increment 3 times.

In the returned results we can see that these commands are submitted to the Redis service one time, and eventually all the server-side responses are read at once

Advantages of Pipeline Technology

The most significant advantage of pipeline technology is the improved performance of the Redis service.

Some test data

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

  1. Require ' RubyGems '
  2. Require ' Redis '
  3. def bench(descr)
  4. Start = time . now
  5. Yield
  6. Puts "#{descr} #{time.now-start} seconds"
  7. End
  8. def without_pipelining
  9. R = Redis. New
  10. 10000.times {
  11. R. Ping
  12. }
  13. End
  14. def with_pipelining
  15. R = Redis. New
  16. R. pipelined {
  17. 10000.times {
  18. R. Ping
  19. }
  20. }
  21. End
  22. Bench("without pipelining") {
  23. Without_pipelining
  24. }
  25. Bench("with pipelining") {
  26. With_pipelining
  27. }

The data from the above simple script on a Mac OS x system on a local area network indicates that the round-trip delay has been improved quite low after the pipeline operation has been turned on.

    1. Without pipelining 1.185238 seconds
    2. With pipelining 0.250783 seconds

As you can see, we've increased our speed efficiency by 5 times times since we opened the pipe.

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.