Pipeline class allows you to batch multiple Redis commands into a single HTTP request, significantly improving performance when executing multiple operations.
Overview
Upstash REST API supports command pipelining to send multiple commands in batch instead of sending each command one by one. When using pipelines, several commands are sent using a single HTTP request, and a single JSON array response is returned.Creating a Pipeline
pipeline()
Create a pipeline for batching commands (non-atomic).multi()
Create a transaction for atomic execution of commands.Methods
exec()
Execute all commands in the pipeline and return results.Array of results corresponding to each command in the pipeline
With Type Inference
When commands are chained, TypeScript automatically infers the return types:Manual Type Annotation
You can manually specify return types when needed:Error Handling
By default, if any command fails, the entire pipeline throws an error:Keep Errors Option
To get individual errors for each command, usekeepErrors: true:
Execution options
When
keepErrors is false (default): Array of command resultsWhen keepErrors is true: Array of objects with:result: The command resulterror: Error message if command failed, undefined otherwise
length()
Get the number of commands in the pipeline before execution.Number of commands queued in the pipeline
Command Methods
All Redis commands available on the Redis client are also available on Pipeline. Commands are chainable:String Commands
Hash Commands
List Commands
Set Commands
Sorted Set Commands
JSON Commands
Usage Patterns
Basic Pipelining
Chaining Commands
Atomic Transactions
Complex Operations
Error Handling with keepErrors
Performance Benefits
Pipelining can dramatically improve performance by reducing round-trip time:TypeScript Examples
Type-Safe Pipeline
Mixing Command Types
Comparison: pipeline() vs multi()
| Feature | pipeline() | multi() |
|---|---|---|
| Atomicity | No - commands can interleave | Yes - all commands execute atomically |
| Use Case | Performance optimization | Transactions requiring consistency |
| Redis Command | Sends multiple commands | Wraps commands in MULTI/EXEC |
| Rollback | Not supported | All or nothing execution |