Redis

Redis Pipelining

Redis Pipelining refers to a feature that allows you to send multiple commands to the Redis server in one go. Instead of sending a command and getting a reply immediately, pipelining will enable you to create a batch command execution and run them on the server simultaneously.

The primary purpose of pipelining is to improve protocol and Redis performance. Furthermore, since all commands are first organized on the client-side, it can reduce the Round Trip Time required for the client to send a request, the server to process it and return a response to the client.

For example, let’s say that each query takes approximately 100 milliseconds. So, if you are running 1000 queries and waiting for a response, it would take 100 * 1000 to process all of them.

However, using pipelining, you can line up all the queries in one big “pile” and tell the server, here you go.

This means, instead of 100 * 1000, you reduce the TTL to that of a single query.

Example of Redis Pipelining

Pipelining is a widespread feature and is supported by all versions of the Redis server. An example of pipeline command is as shown:

$ (echo -en "AUTH default password\r\nPING\r\nPING\r\nSET key value\r\nGET key\r\nINCR newkey\r\nINCR newkey"; sleep 1) | nc localhost 6379

In this case, we start by authenticating to the Redis server and running Ping to check if the server is up. We then set key-value pair and perform INCR operations on a new key. We sleep for 1 second and pass the input via netcat.

The above queries should return:

+OK
+PONG
+PONG
+OK
$5
value
:1

Conclusion

This tutorial shows you how to use Redis pipelining to execute commands in a batch order. This can help reduce the TTL for your queries.

Learn more here.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list