Skip to content

Pipelines

Every Redis command involves a round-trip: the client sends the command, waits for the reply, then sends the next command. Over a network with even modest latency, this adds up quickly.

Pipelining lets the client send a batch of commands in one write, without waiting for each individual reply. The server processes them in order and returns all replies together. The result is a single round-trip instead of N round-trips.

# Without pipelining: 3 round-trips
127.0.0.1:6379> SET a 1
OK
127.0.0.1:6379> SET b 2
OK
127.0.0.1:6379> SET c 3
OK
# With pipelining: 1 round-trip, same results

Most Redis client libraries expose pipelining directly. In Node.js (ioredis), for example:

Terminal window
const pipeline = redis.pipeline();
pipeline.set('a', 1);
pipeline.set('b', 2);
pipeline.set('c', 3);
const results = await pipeline.exec();

The redis-cli tool ships with a --pipe flag that accepts Redis protocol (RESP) on stdin and sends it as a pipeline:

Terminal window
# Generate RESP inline and pipe it to Redis
printf "*3\r\n\$3\r\nSET\r\n\$2\r\nk1\r\n\$5\r\nhello\r\n*3\r\n\$3\r\nSET\r\n\$2\r\nk2\r\n\$5\r\nworld\r\n" \
| redis-cli --pipe

This is useful for bulk imports: tools like redis-cli --pipe can load millions of keys in seconds by sending large batches over a single connection.

You can also generate a text file of commands and pipe them:

Terminal window
# commands.txt contains one redis-cli command per line
cat commands.txt | redis-cli --pipe

Pipelines and transactions are often confused. The table below clarifies the difference:

FeaturePipelineTransaction (MULTI/EXEC)
Round-tripsOne (or few)One per command + EXEC
AtomicityNo — other clients can interleaveYes — no interruption
RollbackNoNo
Use caseThroughput / bulk loadSafe grouped write

A pipeline is a network optimization. A transaction is an atomicity guarantee. You can combine them: many client libraries let you send a MULTI/EXEC block inside a pipeline to get both benefits.

SET a 1
SET b 2
SET c 3
MGET a b c
What is the primary benefit of pipelining in Redis?
When using a pipeline, can other clients' commands interleave with the pipelined commands?
Which redis-cli flag enables pipe mode for bulk imports?
To get both reduced round-trips AND atomicity, you should: