Redis Pipeline

Pipeline lets the client bundle several commands and send them to Redis in one go It doesn’t wait for each command’s response before sending the next one, and it collects all the results at the end.

Running 100 commands normally means 100 round trips between the client and Redis. With Pipeline, all 100 commands are sent together, Redis runs them in order, and the results come back at once, so there’s only 1 round trip.

If network latency is 1 ms, 100 normal commands spend 100 ms just waiting on the network. With Pipeline it’s only 1 ms. The more commands you send and the higher the latency, the more Pipeline helps. (It saves network round-trip time, cutting RTT from N trips to 1.)

Difference between pipeline, transaction and lua

Pipeline does not guarantee atomicity. If you send 10 commands and the 5th one fails, the first 4 are not rolled back and the last 5 still run. Pipeline is only a way to send commands in bulk faster. It has nothing to do with atomicity.

A transaction wraps commands in MULTI/EXEC. This guarantees the batch runs back-to-back without other clients’ commands cutting in, but it doesn’t support rollback either.

A Lua script runs truly atomically. Redis runs the whole script as one command, so nothing can interrupt it partway. However, Lua scripts also can’t roll back on failure.

Feature Pipeline Transaction Lua Script
Atomicity Not guaranteed Commands run back-to-back, no cutting in Whole script runs atomically
Rollback on failure Not supported Not supported Not supported
Conditional logic Not supported Not supported Supported

Use a Lua script when you need atomicity. Use Pipeline when you only need faster bulk operations.