Skip to main content

Overview

Pipelining allows you to send multiple Redis commands in a single HTTP request instead of making separate requests for each command. This dramatically reduces network latency when executing multiple operations.

Why use pipelines?

Without pipelining, each command requires a separate HTTP round-trip:
With pipelining, all commands are sent together:

Basic usage

Create a pipeline, add commands, and execute:

Chaining syntax

You can chain commands for a more concise syntax:

Type inference

When you chain all commands, TypeScript automatically infers the return types:
For manual type specification:

All Redis commands supported

Pipelines support all Redis commands:

JSON commands in pipelines

JSON commands work seamlessly in pipelines:

Error handling

By default, if any command fails, the entire pipeline throws an error:

Keep errors

To get individual errors for each command, use keepErrors:

Pipeline length

Get the number of commands in a pipeline before execution:

Multi-exec (transactions)

For atomic execution of commands, use multi() instead of pipeline():
multi() wraps commands in Redis MULTI/EXEC, guaranteeing atomic execution. Regular pipeline() commands may interleave with other clients’ commands.

Important notes

Non-atomic execution

Pipeline commands are not atomic. Other clients can execute commands between your pipelined commands:
Use multi() for atomic transactions.

Excluded commands

Some commands that return large amounts of data or require iteration cannot be pipelined:
  • scan, hscan, sscan, zscan - Cursor-based iteration
  • keys - Returns all keys
  • hgetall, hkeys, lrange - May return large datasets
  • smembers - Returns all set members
  • zrange - May return large ranges
Use these commands individually outside of pipelines.

Performance benefits

Pipelining reduces latency by eliminating network round-trips:
When to use pipelines:
  • Executing multiple independent commands
  • Batch operations (bulk writes, bulk reads)
  • Reducing latency in serverless environments
  • Optimizing high-throughput scenarios
When to use individual commands:
  • Commands depend on previous results
  • Executing only one or two commands
  • Commands that return large datasets

Advanced example

Batch user creation: