Pipelines
What is pipelining?
Section titled “What is pipelining?”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-trips127.0.0.1:6379> SET a 1OK127.0.0.1:6379> SET b 2OK127.0.0.1:6379> SET c 3OK
# With pipelining: 1 round-trip, same resultsMost Redis client libraries expose pipelining directly. In Node.js (ioredis), for example:
const pipeline = redis.pipeline();pipeline.set('a', 1);pipeline.set('b', 2);pipeline.set('c', 3);const results = await pipeline.exec();redis-cli —pipe mode
Section titled “redis-cli —pipe mode”The redis-cli tool ships with a --pipe flag that accepts Redis protocol (RESP) on stdin and sends it as a pipeline:
# Generate RESP inline and pipe it to Redisprintf "*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 --pipeThis 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:
# commands.txt contains one redis-cli command per linecat commands.txt | redis-cli --pipePipelines vs transactions
Section titled “Pipelines vs transactions”Pipelines and transactions are often confused. The table below clarifies the difference:
| Feature | Pipeline | Transaction (MULTI/EXEC) |
|---|---|---|
| Round-trips | One (or few) | One per command + EXEC |
| Atomicity | No — other clients can interleave | Yes — no interruption |
| Rollback | No | No |
| Use case | Throughput / bulk load | Safe 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