Upstash REST /pipeline: batch commands in one HTTP request, but it is not atomic
Shows how to fix upstash REST /pipeline: batch commands in one HTTP request, but it is not atomic. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
If two commands must run with nothing in between, use /multi-exec instead: curl -X POST https://YOURRESTURL/multi-exec \ -H "your auth header \ -d '[ ["SET", "key1", "valuex"], ["INCR", "key1"] ]' A transaction is discarded as a whole on syntax errors, unsupported commands, oversized requests, or hitting the daily request limit.
Steps
- - You need more throughput: one HTTP round trip instead of many.
Your commands are independent: no later command needs an earlier commands result to be constructed.
- Commands from other clients can interleave with your pipeline. If two
commands must run with nothing in between, use /multi-exec instead:
curl -X POST https://YOURRESTURL/multi-exec \ -H "your auth header \ -d '[ ["SET", "key1", "valuex"], ["INCR", "key1"] ]'
- A transaction is discarded as a whole on syntax errors, unsupported
commands, oversized requests, or hitting the daily request limit. Note that WATCH, UNWATCH, and DISCARD are not supported over REST.
When to use
You are seeing this: POST to /pipeline with a two-dimensional JSON array. Use this skill when you run into "Upstash REST /pipeline: batch commands in one HTTP request, but it is not atomic".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
Edge cases
- Note that WATCH, UNWATCH, and DISCARD are not supported over REST.
Sources
- https://YOURRESTURL/pipeline
- https://YOURRESTURL/multi-exec