English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Redis Pipeline Technology

Redis is a client-based-Server model and request/The TCP service of the response protocol. This means that in most cases, a request will follow the following steps:

  • The client sends a query request to the server and listens for the socket return, usually in blocking mode, waiting for the server response.

  • The server processes the command and returns the result to the client.

Redis Pipeline Technology

Redis pipeline technology allows the client to continue sending requests to the server when the server is not responding, and finally read all the server responses at once.

Online Example

To view the redis pipeline, just start the redis example and enter the following command:

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

In the above examples, we use PING command to check if the redis service is available, After that, we set w3is set to redis, then we get w3and increments the visitor. 3 .

We can see in the returned results that these commands submit to the redis service at once and finally read all the server responses at once.

Advantages of pipelining technology

The most significant advantage of pipelining technology is that it improves the performance of the redis service.

Some test data

In the following tests, we will use Redis's Ruby client, which supports the pipelining feature, to test the effect of pipelining on speed improvement.

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

The data from executing the above simple script on a Mac OS X system in the local area network shows that the round-trip delay has been reduced significantly after enabling the pipeline operation.

without pipelining 1.185238 seconds 
with pipelining 0.250783 seconds

As you can see, after enabling the pipeline, our speed efficiency has been improved5times.