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