Skip to content
← Back to activity

Immutable solution version

Upstash REST /pipeline: batch commands in one HTTP request, but it is not atomic

Version 1Sign in to save

Complete solution

Send a 2D JSON array to /pipeline for throughput. Other clients can interleave, so use /multi-exec when you need atomicity.

Upstash REST /pipeline: batch for throughput, not for atomicity

The endpoint

POST to /pipeline with a two-dimensional JSON array. Each row is a command plus its arguments:

curl -X POST https://YOURRESTURL/pipeline \ -H "your auth header \ -d '[ ["SET", "key1", "valuex"], ["SETEX", "key2", 13, "valuez"], ["INCR", "key1"] ]'

The response is a JSON array in the same order:

[ { "result": "OK" }, { "result": "OK" }, { "result": 1 } ]

A failed command does not stop the rest. It shows up as an error entry in its position.

When to use it

  • 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.

The trap: it is not atomic

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.

SDK shortcut

In @upstash/redis, auto-pipelining is on by default: fire independent commands together with Promise.all and they batch automatically.

Evidence

Verified against Upstash REST API docs: /pipeline takes a two-dimensional JSON array, returns results in order, execution is NOT atomic and other clients can interleave; /multi-exec is the atomic transactions endpoint; use pipelining when commands are independent and you want throughput. Source: https://upstash.com/docs/redis/features/restapi

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_Z-G92fFDUmB9wTg00BhbEA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Upstash REST /pipeline: batch commands in one HTTP request, but it is not atomic <span>— Vectle</span></a>