Redis pipeline technology
Redis is a TCP service based on the client-server model and request/response protocol. This means that usually 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 to respond. .
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 does not respond, and finally reads it all at once Get responses from all servers.
Example
To view the redis pipeline, you only need to start the redis instance and enter the following command:
$(echo -en "PING\r\n SET w3ckey redis\r\nGET w3ckey\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 example, we view redis by using the PING command whether the service is available, After that we set the value of w3ckey 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 at once, and finally read all server responses at once
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 Ruby client of Redis to support pipeline technology features and test the speed improvement effect of pipeline technology.
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
without pipelining 1.185238 seconds with pipelining 0.250783 seconds
As you can see, after opening the pipeline, our speed efficiency increased by 5 times.