Redis Pipeline for Performance Gains
Learn to use Redis pipeline to build high-performance solutions.
Redis pipeline overview
Redis follows a simple request-response pattern where clients, such as applications and Redis CLI, send requests to the Redis server over TCP and wait (block) for the response. Because Redis is a high performance database, this works well in most cases, even at a high volume of requests per second. However, another factor is the network latency between Redis (server) and the client(s). This is independent of Redis performance. Even if Redis is operating at peak performance, we’ll need to incur the cost of back and forth between the client and server for every request, which is called round-trip time.
Redis has a feature called pipeline that can help avoid this and thereby improve performance. By using a pipeline-based connection, we can send multiple commands without waiting for the response of an individual command. You can think of a pipeline as an optimization technique that relies on batching and sending many commands in a single request and collecting all the responses together.
Let’s see a pipeline in action with a demo application.
Application overview
This example will sets the value of multiple items using a for
loop. We’ll first try this by using the normal way (without a pipeline) and then we’ll apply pipelining. Finally, we’ll compare the time taken in both the cases. This will give us a good understanding of the ...