Overview
Auto-pipelining automatically batches multiple Redis commands into a single HTTP request, providing the performance benefits of manual pipelining without requiring explicit pipeline management.How it works
When auto-pipelining is enabled (the default), commands issued in the same event loop tick are automatically batched:- Collects all commands issued in the current tick
- Waits for the next tick (using
Promise.resolve().then()) - Sends all collected commands in a single batch
- Returns individual results to each promise
Enabling auto-pipelining
Auto-pipelining is enabled by default. To explicitly enable or disable:When disabled, each command executes as an individual HTTP request.
Usage patterns
Parallel operations
Execute multiple independent commands efficiently:Sequential with batching
Issue commands sequentially in the same tick:JSON operations
JSON commands are also auto-pipelined:When commands are batched
Commands are batched when issued in the same event loop tick:Performance comparison
Without auto-pipelining
With auto-pipelining
Monitoring pipeline batches
Track how many pipeline batches have been executed:Error handling
Each command’s promise resolves or rejects individually:Excluded commands
Some commands cannot be auto-pipelined and always execute individually:scan,hscan,sscan,zscan- Cursor-based iterationkeys- Returns all keyshgetall,hkeys- May return large datasetslrange- May return large rangessmembers- Returns all set memberszrange- May return large rangesxrange,xrevrange- Stream rangesflushdb,flushall- Destructive operationsdbsize- Database-wide operationexec- Transaction execution
Auto-pipeline vs manual pipeline
When to use auto-pipeline
- Default choice for most applications
- Serverless functions with multiple commands
- Simplified code without manual pipeline management
- When batching can happen naturally via
Promise.all()
When to use manual pipeline
- Need explicit control over batch boundaries
- Want to see exactly which commands are batched
- Building complex batch operations
- Need transaction semantics with
multi()
Real-world example
Serverless function with auto-pipelining:Best practices
-
Issue commands before awaiting: Let the SDK collect multiple commands
-
Use Promise.all() for parallel operations
-
Handle errors individually
-
Monitor pipeline efficiency in development