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