2 min read

Pipeline REST API on Serverless Redis

Enes Akar

Cofounder @Upstash

Pipeline API
Ordering Guarantee and Atomicity

Upstash supports the REST API in addition to the native Redis API. REST API helps developers to access their Redis without connection issues from serverless and edge functions. But if you execute multiple Redis commands in the same function then this means you will make a call to the database multiple times. One of our community members (@MasterGates) came with a great suggestion in our Discord channel. Pipeline API:

pipeline api

Pipeline API

Pipeline API is just adaptation of Redis PIPELINE command to the REST API. You send multiple commands in a single http request, the responses are returned in a single request. This improves the performance of your application by reducing the RTT (round trip time) as well as decreasing the socket I/O.

Request syntax:

curl -X POST \
-H "Authorization: Bearer 2553feg6a2d9842h2a0gcdb5f8efe9934" \
-d '
     ["SET", "key1", "valuex"],
     ["SETEX", "key2", 13, "valuez"],
     ["INCR", "key1"],
     ["ZADD", "myset", 11, "item1", 22, "item2"]

Response syntax:

  { "result": "OK" },
  { "result": "OK" },
  { "error": "ERR value is not an integer or out of range" },
  { "result": 2 }

Ordering Guarantee and Atomicity

Upstash guarantees the commands in the pipeline are executed in the same order. But the atomicity is not guaranteed. Commands sent by other clients can interleave with the pipeline. Some commands may fail while the remaining are executed with success.

Another limitation of pipeline API is your commands should be independent, so response of a command should not be needed by another command in the pipeline.

Check our documentation to learn more about Upstash REST API. We continue to develop the API guided by our users so please share your feedback on twitter or discord.

© 2023 Upstash, Inc. Based in California.

* Redis is a trademark of Redis Ltd. Any rights therein are reserved to Redis Ltd. Any use by Upstash is for referential purposes only and does not indicate any sponsorship, endorsement or affiliation between Redis and Upstash.

** Cloudflare, the Cloudflare logo, and Cloudflare Workers are trademarks and/or registered trademarks of Cloudflare, Inc. in the United States and other jurisdictions.