How do you use pipelining in a Redis client library to reduce the overhead of sending many commands to the server?
Short answer
Pipelining lets you batch several commands together and send them to Redis in a single network round trip, rather than waiting for a response after each individual command, which significantly reduces the cumulative network latency overhead when you need to perform many…
Advertisement
AModel answer
Pipelining lets you batch several commands together and send them to Redis in a single network round trip, rather than waiting for a response after each individual command, which significantly reduces the cumulative network latency overhead when you need to perform many operations at once.
pipe = redis.pipeline()
pipe.set('key1', 'value1')
pipe.set('key2', 'value2')
pipe.set('key3', 'value3')
pipe.execute()Real-world example
A data import process uses pipelining to insert ten thousand records into Redis, completing in a fraction of the time it would have taken to send each command as a separate individual network round trip.
Likely follow-ups
- What is the difference between pipelining and a Redis transaction?
- Is there a practical limit to how many commands should be batched in a single pipeline?
Related topics