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:
- $(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
- +PONG
- +OK
- Redis
- :1
- :2
- :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.
- 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 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.
- Without pipelining 1.185238 seconds
- 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