import { Pipeline } from "https://deno.land/x/upstash_redis@v1.19.3/pkg/pipeline.ts";
Upstash REST API supports command pipelining to send multiple commands in batch, instead of sending each command one by one and waiting for a response. When using pipelines, several commands are sent using a single HTTP request, and a single JSON array response is returned. Each item in the response array corresponds to the command in the same order within the pipeline.
NOTE:
Execution of the pipeline is not atomic. Even though each command in the pipeline will be executed in order, commands sent by other clients can interleave with the pipeline.
Examples:
const p = redis.pipeline() // or redis.multi()
p.set("key","value")
p.get("key")
const res = await p.exec()
You can also chain commands together
const p = redis.pipeline()
const res = await p.set("key","value").get("key").exec()
It's not possible to infer correct types with a dynamic pipeline, so you can override the response type manually:
redis.pipeline()
.set("key", { greeting: "hello"})
.get("key")
.exec<["OK", { greeting: string } ]>()
Constructors
Properties
Send the pipeline request to upstash.
Returns an array with the results of all pipelined commands.
You can define a return type manually to make working in typescript easier
redis.pipeline().get("key").exec<[{ greeting: string }]>()