Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/upstash_redis/pkg/pipeline.ts>Pipeline

HTTP based Redis Client for Serverless and Edge Functions
Extremely Popular
Go to Latest
class Pipeline
import { Pipeline } from "https://deno.land/x/upstash_redis@v1.24.0-next.2/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()

Return types are inferred if all commands are chained, but you can still override the response type manually:

 redis.pipeline()
  .set("key", { greeting: "hello"})
  .get("key")
  .exec<["OK", { greeting: string } ]>()

Constructors

new
Pipeline(opts: { client: Requester; commandOptions?: CommandOptions<any, any>; multiExec?: boolean; })

Type Parameters

optional
TCommands extends Command<any, any>[] = []

Properties

private
client: Requester
private
optional
commandOptions: CommandOptions<any, any>
private
commands: TCommands
private
multiExec: boolean
append: (...args: CommandArgs<AppendCommand>) => unknown
bitcount: (...args: CommandArgs<BitCountCommand>) => unknown
bitop: { (
op: "and" | "or" | "xor",
destinationKey: string,
sourceKey: string,
...sourceKeys: string[],
): Pipeline<[...TCommands, BitOpCommand]>; (
op: "not",
destinationKey: string,
sourceKey: string,
): Pipeline<[...TCommands, BitOpCommand]>; }
bitpos: (...args: CommandArgs<BitPosCommand>) => unknown
dbsize: () => unknown
decr: (...args: CommandArgs<DecrCommand>) => unknown
decrby: (...args: CommandArgs<DecrByCommand>) => unknown
del: (...args: CommandArgs<DelCommand>) => unknown
echo: (...args: CommandArgs<EchoCommand>) => unknown
eval: <TArgs extends unknown[], TData = unknown>(...args: [string, string[], TArgs]) => unknown
evalsha: <TArgs extends unknown[], TData = unknown>(...args: [string, string[], TArgs]) => unknown
exec: <TCommandResults extends unknown[] = [] extends TCommands ? unknown[] : InferResponseData<TCommands>>() => Promise<TCommandResults>

Send the pipeline request to upstash.

Returns an array with the results of all pipelined commands.

If all commands are statically chained from start to finish, types are inferred. You can still define a return type manually if necessary though:

const p = redis.pipeline()
p.get("key")
const result = p.exec<[{ greeting: string }]>()
exists: (...args: CommandArgs<ExistsCommand>) => unknown
expire: (...args: CommandArgs<ExpireCommand>) => unknown
expireat: (...args: CommandArgs<ExpireAtCommand>) => unknown
flushall: (args?: CommandArgs<FlushAllCommand>) => unknown
flushdb: (...args: CommandArgs<FlushDBCommand>) => unknown
get: <TData>(...args: CommandArgs<GetCommand>) => unknown
getbit: (...args: CommandArgs<GetBitCommand>) => unknown
getdel: <TData>(...args: CommandArgs<GetDelCommand>) => unknown
getrange: (...args: CommandArgs<GetRangeCommand>) => unknown
getset: <TData>(key: string, value: TData) => unknown
hdel: (...args: CommandArgs<HDelCommand>) => unknown
hexists: (...args: CommandArgs<HExistsCommand>) => unknown
hget: <TData>(...args: CommandArgs<HGetCommand>) => unknown
hgetall: <TData extends Record<string, unknown>>(...args: CommandArgs<HGetAllCommand>) => unknown
hincrby: (...args: CommandArgs<HIncrByCommand>) => unknown
hincrbyfloat: (...args: CommandArgs<HIncrByFloatCommand>) => unknown
hkeys: (...args: CommandArgs<HKeysCommand>) => unknown
hlen: (...args: CommandArgs<HLenCommand>) => unknown
hmget: <TData extends Record<string, unknown>>(...args: CommandArgs<HMGetCommand>) => unknown
hmset: <TData>(key: string, kv: { [field: string]: TData; }) => unknown
hrandfield: <TData extends string | string[] | Record<string, unknown>>(
key: string,
count?: number,
withValues?: boolean,
) => unknown
hscan: (...args: CommandArgs<HScanCommand>) => unknown
hset: <TData>(key: string, kv: { [field: string]: TData; }) => unknown
hsetnx: <TData>(
key: string,
field: string,
value: TData,
) => unknown
hstrlen: (...args: CommandArgs<HStrLenCommand>) => unknown
hvals: (...args: CommandArgs<HValsCommand>) => unknown
incr: (...args: CommandArgs<IncrCommand>) => unknown
incrby: (...args: CommandArgs<IncrByCommand>) => unknown
incrbyfloat: (...args: CommandArgs<IncrByFloatCommand>) => unknown
readonly
json
keys: (...args: CommandArgs<KeysCommand>) => unknown
lindex: (...args: CommandArgs<LIndexCommand>) => unknown
linsert: <TData>(
key: string,
direction: "before" | "after",
pivot: TData,
value: TData,
) => unknown
llen: (...args: CommandArgs<LLenCommand>) => unknown
lmove: <TData = string>(...args: CommandArgs<LMoveCommand>) => unknown
lpop: <TData>(...args: CommandArgs<LPopCommand>) => unknown
lpos: <TData>(...args: CommandArgs<LPosCommand>) => unknown
lpush: <TData>(key: string, ...elements: TData[]) => unknown
lpushx: <TData>(key: string, ...elements: TData[]) => unknown
lrange: <TResult = string>(...args: CommandArgs<LRangeCommand>) => unknown
lrem: <TData>(
key: string,
count: number,
value: TData,
) => unknown
lset: <TData>(
key: string,
index: number,
value: TData,
) => unknown
ltrim: (...args: CommandArgs<LTrimCommand>) => unknown
mget: <TData extends unknown[]>(...args: CommandArgs<MGetCommand>) => unknown
mset: <TData>(kv: { [key: string]: TData; }) => unknown
msetnx: <TData>(kv: { [key: string]: TData; }) => unknown
persist: (...args: CommandArgs<PersistCommand>) => unknown
pexpire: (...args: CommandArgs<PExpireCommand>) => unknown
pexpireat: (...args: CommandArgs<PExpireAtCommand>) => unknown
ping: (args?: CommandArgs<PingCommand>) => unknown
psetex: <TData>(
key: string,
ttl: number,
value: TData,
) => unknown
pttl: (...args: CommandArgs<PTtlCommand>) => unknown
publish: (...args: CommandArgs<PublishCommand>) => unknown
randomkey: () => unknown
rename: (...args: CommandArgs<RenameCommand>) => unknown
renamenx: (...args: CommandArgs<RenameNXCommand>) => unknown
rpop: <TData = string>(...args: CommandArgs<RPopCommand>) => unknown
rpush: <TData>(key: string, ...elements: TData[]) => unknown
rpushx: <TData>(key: string, ...elements: TData[]) => unknown
sadd: <TData>(key: string, ...members: TData[]) => unknown
scan: (...args: CommandArgs<ScanCommand>) => unknown
scard: (...args: CommandArgs<SCardCommand>) => unknown
scriptExists: (...args: CommandArgs<ScriptExistsCommand>) => unknown
scriptFlush: (...args: CommandArgs<ScriptFlushCommand>) => unknown
scriptLoad: (...args: CommandArgs<ScriptLoadCommand>) => unknown
sdiff: (...args: CommandArgs<SDiffCommand>) => unknown
sdiffstore: (...args: CommandArgs<SDiffStoreCommand>) => unknown
set: <TData>(
key: string,
value: TData,
) => unknown
setbit: (...args: CommandArgs<SetBitCommand>) => unknown
setex: <TData>(
key: string,
ttl: number,
value: TData,
) => unknown
setnx: <TData>(key: string, value: TData) => unknown
setrange: (...args: CommandArgs<SetRangeCommand>) => unknown
sinter: (...args: CommandArgs<SInterCommand>) => unknown
sinterstore: (...args: CommandArgs<SInterStoreCommand>) => unknown
sismember: <TData>(key: string, member: TData) => unknown
smembers: <TData extends unknown[] = string[]>(...args: CommandArgs<SMembersCommand>) => unknown
smismember: <TMembers extends unknown[]>(key: string, members: TMembers) => unknown
smove: <TData>(
source: string,
destination: string,
member: TData,
) => unknown
spop: <TData>(...args: CommandArgs<SPopCommand>) => unknown
srandmember: <TData>(...args: CommandArgs<SRandMemberCommand>) => unknown
srem: <TData>(key: string, ...members: TData[]) => unknown
sscan: (...args: CommandArgs<SScanCommand>) => unknown
strlen: (...args: CommandArgs<StrLenCommand>) => unknown
sunion: (...args: CommandArgs<SUnionCommand>) => unknown
sunionstore: (...args: CommandArgs<SUnionStoreCommand>) => unknown
time: () => unknown
touch: (...args: CommandArgs<TouchCommand>) => unknown
ttl: (...args: CommandArgs<TtlCommand>) => unknown
type: (...args: CommandArgs<TypeCommand>) => unknown
zadd: <TData>(...args: [string, ScoreMember<TData>, ScoreMember<TData>[]] | [string, ZAddCommandOptions | ZAddCommandOptionsWithIncr, [ScoreMember<TData>, ...ScoreMember<TData>[]]]) => unknown
zcard: (...args: CommandArgs<ZCardCommand>) => unknown
zcount: (...args: CommandArgs<ZCountCommand>) => unknown
zdiffstore: (...args: CommandArgs<ZDiffStoreCommand>) => unknown
zincrby: <TData>(
key: string,
increment: number,
member: TData,
) => unknown
zinterstore: (...args: CommandArgs<ZInterStoreCommand>) => unknown
zlexcount: (...args: CommandArgs<ZLexCountCommand>) => unknown
zmscore: (...args: CommandArgs<ZMScoreCommand>) => unknown
zpopmax: <TData>(...args: CommandArgs<ZPopMaxCommand>) => unknown
zpopmin: <TData>(...args: CommandArgs<ZPopMinCommand>) => unknown
zrange: <TData extends unknown[]>(...args:
[
string,
number,
number,
]
|
[
string,
| `(${string}`
| `[${string}`
| "-"
| "+"
,
| `(${string}`
| `[${string}`
| "-"
| "+"
,
{ byLex: true; } & ZRangeCommandOptions,
]
|
[
string,
| number
| `(${number}`
| "-inf"
| "+inf"
,
| number
| `(${number}`
| "-inf"
| "+inf"
,
{ byScore: true; } & ZRangeCommandOptions,
]
) => unknown
zrank: <TData>(key: string, member: TData) => unknown
zrem: <TData>(key: string, ...members: TData[]) => unknown
zremrangebylex: (...args: CommandArgs<ZRemRangeByLexCommand>) => unknown
zremrangebyrank: (...args: CommandArgs<ZRemRangeByRankCommand>) => unknown
zremrangebyscore: (...args: CommandArgs<ZRemRangeByScoreCommand>) => unknown
zrevrank: <TData>(key: string, member: TData) => unknown
zscan: (...args: CommandArgs<ZScanCommand>) => unknown
zscore: <TData>(key: string, member: TData) => unknown
zunion: (...args: CommandArgs<ZUnionCommand>) => unknown
zunionstore: (...args: CommandArgs<ZUnionStoreCommand>) => unknown

Methods

private
chain<T>(command: Command<any, T>): Pipeline<[...TCommands, Command<any, T>]>

Pushes a command into the pipeline and returns a chainable instance of the pipeline

length(): number

Returns the length of pipeline before the execution