⚠️ Internal: This API is not publically exported by the package.

Serverless redis client for upstash.

Hierarchy

Accessors

  • get json(): {
        arrappend: ((key, path, ...values) => Promise<number[]>);
        arrindex: ((key, path, value, start?, stop?) => Promise<number[]>);
        arrinsert: ((key, path, index, ...values) => Promise<number[]>);
        arrlen: ((key, path?) => Promise<number[]>);
        arrpop: ((key, path?, index?) => Promise<unknown[]>);
        arrtrim: ((key, path?, start?, stop?) => Promise<number[]>);
        clear: ((key, path?) => Promise<number>);
        del: ((key, path?) => Promise<number>);
        forget: ((key, path?) => Promise<number>);
        geoadd: ((args_0, args_1, ...args_2) => Promise<number>);
        geodist: ((key, member1, member2, unit?) => Promise<number>);
        geohash: ((args_0, ...args_1) => Promise<string[]>);
        geopos: ((args_0, ...args_1) => Promise<{
            lat: number;
            lng: number;
        }[]>);
        geosearch: ((key, centerPoint, shape, order, opts?) => Promise<({
            member: unknown;
        } & {
            coord?: {
                lat: number;
                long: number;
            };
            dist?: number;
            hash?: string;
        })[]>);
        geosearchstore: ((destination, key, centerPoint, shape, order, opts?) => Promise<number>);
        get: ((...args) => Promise<any>);
        mget: ((keys, path) => Promise<any>);
        numincrby: ((key, path, value) => Promise<number[]>);
        nummultby: ((key, path, value) => Promise<number[]>);
        objkeys: ((key, path?) => Promise<string[][]>);
        objlen: ((key, path?) => Promise<number[]>);
        resp: ((key, path?) => Promise<any>);
        set: ((key, path, value, opts?) => Promise<"OK">);
        strappend: ((key, path, value) => Promise<number[]>);
        strlen: ((key, path?) => Promise<number[]>);
        toggle: ((key, path) => Promise<number[]>);
        type: ((key, path?) => Promise<string[]>);
    }
  • Returns {
        arrappend: ((key, path, ...values) => Promise<number[]>);
        arrindex: ((key, path, value, start?, stop?) => Promise<number[]>);
        arrinsert: ((key, path, index, ...values) => Promise<number[]>);
        arrlen: ((key, path?) => Promise<number[]>);
        arrpop: ((key, path?, index?) => Promise<unknown[]>);
        arrtrim: ((key, path?, start?, stop?) => Promise<number[]>);
        clear: ((key, path?) => Promise<number>);
        del: ((key, path?) => Promise<number>);
        forget: ((key, path?) => Promise<number>);
        geoadd: ((args_0, args_1, ...args_2) => Promise<number>);
        geodist: ((key, member1, member2, unit?) => Promise<number>);
        geohash: ((args_0, ...args_1) => Promise<string[]>);
        geopos: ((args_0, ...args_1) => Promise<{
            lat: number;
            lng: number;
        }[]>);
        geosearch: ((key, centerPoint, shape, order, opts?) => Promise<({
            member: unknown;
        } & {
            coord?: {
                lat: number;
                long: number;
            };
            dist?: number;
            hash?: string;
        })[]>);
        geosearchstore: ((destination, key, centerPoint, shape, order, opts?) => Promise<number>);
        get: ((...args) => Promise<any>);
        mget: ((keys, path) => Promise<any>);
        numincrby: ((key, path, value) => Promise<number[]>);
        nummultby: ((key, path, value) => Promise<number[]>);
        objkeys: ((key, path?) => Promise<string[][]>);
        objlen: ((key, path?) => Promise<number[]>);
        resp: ((key, path?) => Promise<any>);
        set: ((key, path, value, opts?) => Promise<"OK">);
        strappend: ((key, path, value) => Promise<number[]>);
        strlen: ((key, path?) => Promise<number[]>);
        toggle: ((key, path) => Promise<number[]>);
        type: ((key, path?) => Promise<string[]>);
    }

    • arrappend: ((key, path, ...values) => Promise<number[]>)
    • arrindex: ((key, path, value, start?, stop?) => Promise<number[]>)
    • arrinsert: ((key, path, index, ...values) => Promise<number[]>)
    • arrlen: ((key, path?) => Promise<number[]>)
    • arrpop: ((key, path?, index?) => Promise<unknown[]>)
    • arrtrim: ((key, path?, start?, stop?) => Promise<number[]>)
    • clear: ((key, path?) => Promise<number>)
    • del: ((key, path?) => Promise<number>)
    • forget: ((key, path?) => Promise<number>)
    • geoadd: ((args_0, args_1, ...args_2) => Promise<number>)
    • geodist: ((key, member1, member2, unit?) => Promise<number>)
    • geohash: ((args_0, ...args_1) => Promise<string[]>)
    • geopos: ((args_0, ...args_1) => Promise<{
          lat: number;
          lng: number;
      }[]>)
    • geosearch: ((key, centerPoint, shape, order, opts?) => Promise<({
          member: unknown;
      } & {
          coord?: {
              lat: number;
              long: number;
          };
          dist?: number;
          hash?: string;
      })[]>)
        • (key, centerPoint, shape, order, opts?): Promise<({
              member: unknown;
          } & {
              coord?: {
                  lat: number;
                  long: number;
              };
              dist?: number;
              hash?: string;
          })[]>
        • Parameters

          • key: string
          • centerPoint: {
                coordinate: {
                    lat: number;
                    lon: number;
                };
                type: "FROMLONLAT" | "fromlonlat";
            } | {
                member: unknown;
                type: "FROMMEMBER" | "frommember";
            }
          • shape: {
                radius: number;
                radiusType: "M" | "KM" | "FT" | "MI";
                type: "BYRADIUS" | "byradius";
            } | {
                rect: {
                    height: number;
                    width: number;
                };
                rectType: "M" | "KM" | "FT" | "MI";
                type: "BYBOX" | "bybox";
            }
          • order: "ASC" | "DESC" | "asc" | "desc"
          • Optional opts: {
                count?: {
                    any?: boolean;
                    limit: number;
                };
                withCoord?: boolean;
                withDist?: boolean;
                withHash?: boolean;
            }
            • Optional count?: {
                  any?: boolean;
                  limit: number;
              }
              • Optional any?: boolean
              • limit: number
            • Optional withCoord?: boolean
            • Optional withDist?: boolean
            • Optional withHash?: boolean

          Returns Promise<({
              member: unknown;
          } & {
              coord?: {
                  lat: number;
                  long: number;
              };
              dist?: number;
              hash?: string;
          })[]>

    • geosearchstore: ((destination, key, centerPoint, shape, order, opts?) => Promise<number>)
        • (destination, key, centerPoint, shape, order, opts?): Promise<number>
        • Parameters

          • destination: string
          • key: string
          • centerPoint: {
                coordinate: {
                    lat: number;
                    lon: number;
                };
                type: "FROMLONLAT" | "fromlonlat";
            } | {
                member: unknown;
                type: "FROMMEMBER" | "frommember";
            }
          • shape: {
                radius: number;
                radiusType: "M" | "KM" | "FT" | "MI";
                type: "BYRADIUS" | "byradius";
            } | {
                rect: {
                    height: number;
                    width: number;
                };
                rectType: "M" | "KM" | "FT" | "MI";
                type: "BYBOX" | "bybox";
            }
          • order: "ASC" | "DESC" | "asc" | "desc"
          • Optional opts: {
                count?: {
                    any?: boolean;
                    limit: number;
                };
                storeDist?: boolean;
            }
            • Optional count?: {
                  any?: boolean;
                  limit: number;
              }
              • Optional any?: boolean
              • limit: number
            • Optional storeDist?: boolean

          Returns Promise<number>

    • get: ((...args) => Promise<any>)
        • (...args): Promise<any>
        • Parameters

          • Rest ...args: [key: string, opts?: {
                indent?: string;
                newline?: string;
                space?: string;
            }, ...path: string[]] | [key: string, ...path: string[]]

          Returns Promise<any>

    • mget: ((keys, path) => Promise<any>)
    • numincrby: ((key, path, value) => Promise<number[]>)
    • nummultby: ((key, path, value) => Promise<number[]>)
    • objkeys: ((key, path?) => Promise<string[][]>)
    • objlen: ((key, path?) => Promise<number[]>)
    • resp: ((key, path?) => Promise<any>)
    • set: ((key, path, value, opts?) => Promise<"OK">)
        • (key, path, value, opts?): Promise<"OK">
        • Parameters

          • key: string
          • path: string
          • value: string | number | boolean | Record<string, unknown> | (string | number | boolean | Record<string, unknown>)[]
          • Optional opts: {
                nx: true;
                xx?: undefined;
            } | {
                nx?: undefined;
                xx: true;
            }

          Returns Promise<"OK">

    • strappend: ((key, path, value) => Promise<number[]>)
    • strlen: ((key, path?) => Promise<number[]>)
    • toggle: ((key, path) => Promise<number[]>)
    • type: ((key, path?) => Promise<string[]>)

Constructors

  • Create a new redis client by providing the url and token

    Parameters

    Returns Redis

    Example

    const redis = new Redis({
    url: "<UPSTASH_REDIS_REST_URL>",
    token: "<UPSTASH_REDIS_REST_TOKEN>",
    });
  • Create a new redis client by providing a custom Requester implementation

    Parameters

    Returns Redis

    Example


    import { UpstashRequest, Requester, UpstashResponse, Redis } from "@upstash/redis"

    const requester: Requester = {
    request: <TResult>(req: UpstashRequest): Promise<UpstashResponse<TResult>> => {
    // ...
    }
    }

    const redis = new Redis(requester)

Methods

  • Create a new Upstash Redis instance from environment variables.

    Use this to automatically load connection secrets from your environment variables. For instance when using the Vercel integration.

    This tries to load UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN from your environment using process.env.

    Parameters

    Returns Redis

Properties

addTelemetry: ((telemetry) => void)

Type declaration

    • (telemetry): void
    • Technically this is not private, we can hide it from intellisense by doing this

      Parameters

      Returns void

append: ((key, value) => Promise<number>)

Type declaration

bitcount: ((key, start, end) => Promise<number>)

Type declaration

bitop: {
    (op, destinationKey, sourceKey, ...sourceKeys): Promise<number>;
    (op, destinationKey, sourceKey): Promise<number>;
}

Type declaration

bitpos: ((key, bit, start?, end?) => Promise<number>)

Type declaration

client: Requester
copy: ((key, destinationKey, opts?) => Promise<"COPIED" | "NOT_COPIED">)

Type declaration

    • (key, destinationKey, opts?): Promise<"COPIED" | "NOT_COPIED">
    • Parameters

      • key: string
      • destinationKey: string
      • Optional opts: {
            replace: boolean;
        }
        • replace: boolean

      Returns Promise<"COPIED" | "NOT_COPIED">

dbsize: (() => Promise<number>)

Type declaration

decr: ((key) => Promise<number>)

Type declaration

decrby: ((key, decrement) => Promise<number>)

Type declaration

del: ((...args) => Promise<number>)

Type declaration

echo: ((message) => Promise<string>)

Type declaration

enableTelemetry: boolean
eval: (<TArgs, TData>(script, keys, args) => Promise<TData>)

Type declaration

evalsha: (<TArgs, TData>(sha1, keys, args) => Promise<TData>)

Type declaration

exists: ((...args) => Promise<number>)

Type declaration

expire: ((key, seconds) => Promise<0 | 1>)

Type declaration

expireat: ((key, unix) => Promise<0 | 1>)

Type declaration

flushall: ((args?) => Promise<"OK">)

Type declaration

flushdb: ((opts?) => Promise<"OK">)

Type declaration

get: (<TData>(key) => Promise<TData>)

Type declaration

getbit: ((key, offset) => Promise<0 | 1>)

Type declaration

getdel: (<TData>(key) => Promise<TData>)

Type declaration

getrange: ((key, start, end) => Promise<string>)

Type declaration

getset: (<TData>(key, value) => Promise<TData>)

Type declaration

hdel: ((key, ...fields) => Promise<0 | 1>)

Type declaration

hexists: ((key, field) => Promise<number>)

Type declaration

hget: (<TData>(key, field) => Promise<TData>)

Type declaration

hgetall: (<TData>(key) => Promise<TData>)

Type declaration

hincrby: ((key, field, increment) => Promise<number>)

Type declaration

hincrbyfloat: ((key, field, increment) => Promise<number>)

Type declaration

hkeys: ((key) => Promise<string[]>)

Type declaration

hlen: ((key) => Promise<number>)

Type declaration

hmget: (<TData>(key, ...fields) => Promise<TData>)

Type declaration

hmset: (<TData>(key, kv) => Promise<"OK">)

Type declaration

hrandfield: {
    (key): Promise<string>;
    (key, count): Promise<string[]>;
    <TData>(key, count, withValues): Promise<Partial<TData>>;
}

Type declaration

hscan: ((key, cursor, cmdOpts?) => Promise<[number, (string | number)[]]>)

Type declaration

hset: (<TData>(key, kv) => Promise<number>)

Type declaration

hsetnx: (<TData>(key, field, value) => Promise<0 | 1>)

Type declaration

hstrlen: ((key, field) => Promise<number>)

Type declaration

hvals: ((key) => Promise<any>)

Type declaration

incr: ((key) => Promise<number>)

Type declaration

incrby: ((key, value) => Promise<number>)

Type declaration

incrbyfloat: ((key, value) => Promise<number>)

Type declaration

keys: ((pattern) => Promise<string[]>)

Type declaration

lindex: ((key, index) => Promise<any>)

Type declaration

linsert: (<TData>(key, direction, pivot, value) => Promise<number>)

Type declaration

llen: ((key) => Promise<number>)

Type declaration

lmove: (<TData>(source, destination, whereFrom, whereTo) => Promise<TData>)

Type declaration

    • <TData>(source, destination, whereFrom, whereTo): Promise<TData>
    • Type Parameters

      • TData = string

      Parameters

      • source: string
      • destination: string
      • whereFrom: "left" | "right"
      • whereTo: "left" | "right"

      Returns Promise<TData>

lpop: (<TData>(key, count?) => Promise<TData>)

Type declaration

lpos: (<TData>(key, element, opts?) => Promise<TData>)

Type declaration

    • <TData>(key, element, opts?): Promise<TData>
    • Type Parameters

      • TData = number

      Parameters

      • key: string
      • element: unknown
      • Optional opts: {
            count?: number;
            maxLen?: number;
            rank?: number;
        }
        • Optional count?: number
        • Optional maxLen?: number
        • Optional rank?: number

      Returns Promise<TData>

lpush: (<TData>(key, ...elements) => Promise<number>)

Type declaration

lpushx: (<TData>(key, ...elements) => Promise<number>)

Type declaration

lrange: (<TResult>(key, start, end) => Promise<TResult[]>)

Type declaration

lrem: (<TData>(key, count, value) => Promise<number>)

Type declaration

lset: (<TData>(key, index, value) => Promise<"OK">)

Type declaration

ltrim: ((key, start, end) => Promise<"OK">)

Type declaration

mget: (<TData>(...args) => Promise<TData>)

Type declaration

mset: (<TData>(kv) => Promise<"OK">)

Type declaration

msetnx: (<TData>(kv) => Promise<number>)

Type declaration

multi: (() => Pipeline<[]>)

Type declaration

    • (): Pipeline<[]>
    • Create a new transaction to allow executing multiple steps atomically.

      All the commands in a transaction are serialized and executed sequentially. A request sent by another client will never be served in the middle of the execution of a Redis Transaction. This guarantees that the commands are executed as a single isolated operation.

      Returns Pipeline<[]>

opts?: CommandOptions<any, any>
persist: ((key) => Promise<0 | 1>)

Type declaration

pexpire: ((key, milliseconds) => Promise<0 | 1>)

Type declaration

pexpireat: ((key, unix) => Promise<0 | 1>)

Type declaration

pfadd: ((args_0, ...args_1) => Promise<number>)

Type declaration

pfcount: ((args_0, ...args_1) => Promise<number>)

Type declaration

pfmerge: ((destination_key, ...args_1) => Promise<"OK">)

Type declaration

ping: ((args?) => Promise<string>)

Type declaration

pipeline: (() => Pipeline<[]>)

Type declaration

psetex: (<TData>(key, ttl, value) => Promise<string>)

Type declaration

pttl: ((key) => Promise<number>)

Type declaration

publish: ((channel, message) => Promise<number>)

Type declaration

randomkey: (() => Promise<string>)

Type declaration

rename: ((source, destination) => Promise<"OK">)

Type declaration

renamenx: ((source, destination) => Promise<0 | 1>)

Type declaration

rpop: (<TData>(key, count?) => Promise<TData>)

Type declaration

rpush: (<TData>(key, ...elements) => Promise<number>)

Type declaration

rpushx: (<TData>(key, ...elements) => Promise<number>)

Type declaration

sadd: (<TData>(key, ...members) => Promise<number>)

Type declaration

scan: ((cursor, opts?) => Promise<[number, string[]]>)

Type declaration

scard: ((key) => Promise<number>)

Type declaration

scriptExists: ((...args) => Promise<number[]>)

Type declaration

scriptFlush: ((opts?) => Promise<"OK">)

Type declaration

scriptLoad: ((script) => Promise<string>)

Type declaration

sdiff: ((key, ...keys) => Promise<unknown[]>)

Type declaration

sdiffstore: ((destination, ...keys) => Promise<number>)

Type declaration

set: (<TData>(key, value, opts?) => Promise<"OK" | TData>)

Type declaration

setbit: ((key, offset, value) => Promise<0 | 1>)

Type declaration

setex: (<TData>(key, ttl, value) => Promise<"OK">)

Type declaration

setnx: (<TData>(key, value) => Promise<number>)

Type declaration

setrange: ((key, offset, value) => Promise<number>)

Type declaration

sinter: ((key, ...keys) => Promise<string[]>)

Type declaration

sinterstore: ((destination, key, ...keys) => Promise<number>)

Type declaration

sismember: (<TData>(key, member) => Promise<0 | 1>)

Type declaration

smembers: (<TData>(key) => Promise<TData>)

Type declaration

smismember: (<TMembers>(key, members) => Promise<(0 | 1)[]>)

Type declaration

smove: (<TData>(source, destination, member) => Promise<0 | 1>)

Type declaration

spop: (<TData>(key, count?) => Promise<TData>)

Type declaration

srandmember: (<TData>(key, count?) => Promise<TData>)

Type declaration

srem: (<TData>(key, ...members) => Promise<number>)

Type declaration

sscan: ((key, cursor, opts?) => Promise<[number, (string | number)[]]>)

Type declaration

strlen: ((key) => Promise<number>)

Type declaration

sunion: ((key, ...keys) => Promise<unknown[]>)

Type declaration

sunionstore: ((destination, key, ...keys) => Promise<number>)

Type declaration

time: (() => Promise<[number, number]>)

Type declaration

touch: ((...args) => Promise<number>)

Type declaration

ttl: ((key) => Promise<number>)

Type declaration

type: ((key) => Promise<Type>)

Type declaration

unlink: ((...args) => Promise<number>)

Type declaration

use: (<TResult>(middleware) => void)

Type declaration

xadd: ((key, id, entries, opts?) => Promise<string>)

Type declaration

    • (key, id, entries, opts?): Promise<string>
    • Parameters

      • key: string
      • id: string
      • entries: {
            [field: string]: unknown;
        }
        • [field: string]: unknown
      • Optional opts: {
            nomkStream?: boolean;
            trim?: {
                comparison: "~" | "=";
                limit?: number;
                threshold: string | number;
                type: "MAXLEN" | "maxlen" | "MINID" | "minid";
            };
        }
        • Optional nomkStream?: boolean
        • Optional trim?: {
              comparison: "~" | "=";
              limit?: number;
              threshold: string | number;
              type: "MAXLEN" | "maxlen" | "MINID" | "minid";
          }
          • comparison: "~" | "="
          • Optional limit?: number
          • threshold: string | number
          • type: "MAXLEN" | "maxlen" | "MINID" | "minid"

      Returns Promise<string>

xrange: ((key, start, end, count?) => Promise<Record<string, Record<string, unknown>>>)

Type declaration

zadd: (<TData>(...args) => Promise<number>)

Type declaration

zcard: ((key) => Promise<number>)

Type declaration

zcount: ((key, min, max) => Promise<number>)

Type declaration

zdiffstore: ((destination, numkeys, ...keys) => Promise<number>)

Type declaration

zincrby: (<TData>(key, increment, member) => Promise<number>)

Type declaration

zinterstore: ((destination, numKeys, keys, opts?) => Promise<number>)

Type declaration

zlexcount: ((key, min, max) => Promise<number>)

Type declaration

zmscore: ((key, members) => Promise<number[]>)

Type declaration

zpopmax: (<TData>(key, count?) => Promise<TData[]>)

Type declaration

zpopmin: (<TData>(key, count?) => Promise<TData[]>)

Type declaration

zrange: (<TData>(...args) => Promise<TData>)

Type declaration

    • <TData>(...args): Promise<TData>
    • Type Parameters

      • TData extends unknown[]

      Parameters

      • Rest ...args: [key: string, min: number, max: number, opts?: ZRangeCommandOptions] | [key: string, min: `(${string}` | `[${string}` | "-" | "+", max: `(${string}` | `[${string}` | "-" | "+", opts: {
            byLex: true;
            byScore?: true;
            count?: number;
            offset?: number;
            rev?: boolean;
            withScores?: boolean;
        }] | [key: string, min: number | `(${number}` | "-inf" | "+inf", max: number | `(${number}` | "-inf" | "+inf", opts: {
            byLex?: true;
            byScore: true;
            count?: number;
            offset?: number;
            rev?: boolean;
            withScores?: boolean;
        }]

      Returns Promise<TData>

zrank: (<TData>(key, member) => Promise<number>)

Type declaration

zrem: (<TData>(key, ...members) => Promise<number>)

Type declaration

zremrangebylex: ((key, min, max) => Promise<number>)

Type declaration

zremrangebyrank: ((key, start, stop) => Promise<number>)

Type declaration

zremrangebyscore: ((key, min, max) => Promise<number>)

Type declaration

zrevrank: (<TData>(key, member) => Promise<number>)

Type declaration

zscan: ((key, cursor, opts?) => Promise<[number, (string | number)[]]>)

Type declaration

zscore: (<TData>(key, member) => Promise<number>)

Type declaration

zunion: ((numKeys, keys, opts?) => Promise<any>)

Type declaration

zunionstore: ((destination, numKeys, keys, opts?) => Promise<number>)

Type declaration