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 passenableAutoPipelining: true
when creating the Redis client:
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:Promise.all
:
Promise.all
are executed in the order they are written!