Skip to main content
The 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.
Execution is not atomic: Commands in a pipeline are executed in order, but commands from other clients can interleave. Use multi() for atomic transactions.

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.
results
TCommandResults[]
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, use keepErrors: true:
options
{ keepErrors?: boolean }
Execution options
results
Array
When keepErrors is false (default): Array of command resultsWhen keepErrors is true: Array of objects with:
  • result: The command result
  • error: Error message if command failed, undefined otherwise

length()

Get the number of commands in the pipeline before execution.
length
number
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()

Featurepipeline()multi()
AtomicityNo - commands can interleaveYes - all commands execute atomically
Use CasePerformance optimizationTransactions requiring consistency
Redis CommandSends multiple commandsWraps commands in MULTI/EXEC
RollbackNot supportedAll or nothing execution