Auto-Pipelining
Auto Pipelining
Auto pipelining allows you to use the Redis client as usual while in the background it tries to send requests in batches whenever possible.
In a nutshell, the client will accumulate commands in a pipeline and wait for a short amount of time for more commands to arrive. When there are no more commands, it will execute them as a batch.
To enable the feature, simply pass enableAutoPipelining: true
when creating the Redis client:
This is especially useful in cases when we want to make async requests or when we want to make requests in batches.
The benefit of auto pipelining is that it reduces the number of HTTP requests made like pipelining and transaction while being extremely simple to enable and use. It’s especially useful in cases like Vercel Edge and Cloudflare Workers, where the number of simultaneous requests is limited by 6.
To learn more about how auto pipelining can be utilized in a
project, see
the auto-pipeline example project under upstash-redis
repository
How it Works
For auto pipeline to work, the client keeps an active pipeline and adds incoming commands to this pipeline. After the command is added to the pipeline, execution of the pipeline is delayed by releasing the control of the Node thread.
The pipeline executes when one of these two conditions are met: No more commands are being added or at least one of the commands added is being ‘awaited’.
This means that if you are awaiting every time you run a command, you won’t benefit much from auto pipelining since each await will trigger a pipeline:
In these cases, we suggest using Promise.all
:
In addition to resulting in a single PIPELINE call, the commands
in Promise.all
are executed in the order they are written!
Was this page helpful?