prorm API Reference
    Preparing search index...

    Class RedisStore

    RedisStore wraps an ioredis client and exposes Redis's data-structure commands (string/hash/list/set/sorted-set/stream), pub/sub, and pipelining as a typed, promise-based API.

    Implements

    Index
    name: "redis" = 'redis'

    The name of the store (e.g. 'mongodb', 'redis', 'dynamodb')

    library: "ioredis" = 'ioredis'

    The client library being used

    • Serialize a value with JSON.stringify and SET it.

      Type Parameters

      • T

      Parameters

      Returns Promise<"OK" | null>

    • GET a key and JSON.parse it. Returns null if the key is missing.

      Type Parameters

      • T

      Parameters

      • key: string

      Returns Promise<T | null>

    • Parameters

      • key: string

      Returns Promise<string | null>

    • Parameters

      • key: string
      • value: string | number
      • options: SetOptions = {}

      Returns Promise<"OK" | null>

    • Parameters

      • ...keys: string[]

      Returns Promise<number>

    • Parameters

      • ...keys: string[]

      Returns Promise<number>

    • Parameters

      • key: string
      • amount: number

      Returns Promise<number>

    • Parameters

      • key: string
      • seconds: number

      Returns Promise<number>

    • Parameters

      • key: string
      • field: string

      Returns Promise<string | null>

    • Parameters

      • key: string
      • fields: Record<string, string | number>

      Returns Promise<number>

    • Parameters

      • key: string

      Returns Promise<Record<string, string>>

    • Parameters

      • key: string
      • ...fields: string[]

      Returns Promise<number>

    • Parameters

      • key: string
      • field: string
      • amount: number

      Returns Promise<number>

    • Parameters

      • key: string
      • ...values: (string | number)[]

      Returns Promise<number>

    • Parameters

      • key: string
      • ...values: (string | number)[]

      Returns Promise<number>

    • Parameters

      • key: string
      • start: number
      • stop: number

      Returns Promise<string[]>

    • Parameters

      • key: string
      • Optionalcount: number

      Returns Promise<string | string[] | null>

    • Parameters

      • key: string
      • Optionalcount: number

      Returns Promise<string | string[] | null>

    • Parameters

      • key: string
      • ...members: string[]

      Returns Promise<number>

    • Parameters

      • key: string
      • ...members: string[]

      Returns Promise<number>

    • Parameters

      • key: string

      Returns Promise<string[]>

    • Parameters

      • key: string
      • member: string

      Returns Promise<boolean>

    • Parameters

      • key: string
      • start: number
      • stop: number
      • options: ZRangeOptions = {}

      Returns Promise<string[]>

    • Parameters

      • key: string
      • min: string | number
      • max: string | number
      • options: Omit<ZRangeOptions, "rev"> = {}

      Returns Promise<string[]>

    • Parameters

      • key: string
      • ...members: string[]

      Returns Promise<number>

    • Parameters

      • key: string
      • member: string

      Returns Promise<string | null>

    • XADD - append an entry to a stream, creating it if it doesn't exist. Pass '*' as id to let Redis auto-generate a monotonic <ms>-<seq> ID (the common case); returns the ID that was assigned.

      Parameters

      • key: string
      • id: string
      • fields: Record<string, string | number>

      Returns Promise<string>

    • XRANGE - read entries with IDs between start and end (inclusive), in ID order. Use '-'/'+' for the full range.

      Parameters

      • key: string
      • start: string
      • end: string
      • Optionalcount: number

      Returns Promise<StreamEntry[]>

    • XREVRANGE - like xrange() but in reverse ID order; start is the higher/first ID, end the lower/last.

      Parameters

      • key: string
      • start: string
      • end: string
      • Optionalcount: number

      Returns Promise<StreamEntry[]>

    • XREAD - read entries newer than ids from one or more streams. keys[i] is paired with ids[i]; pass '$' for an ID to only read entries added after the call starts, or '0' to read from the beginning. With options.block, blocks (up to that many ms, or forever if 0) waiting for new entries instead of returning immediately. Returns null if nothing matched (e.g. a non-blocking read found nothing new).

      Parameters

      • keys: string[]
      • ids: string[]
      • options: XReadOptions = {}

      Returns Promise<StreamReadResult[] | null>

    • XLEN - number of entries in a stream.

      Parameters

      • key: string

      Returns Promise<number>

    • XDEL - remove specific entries from a stream by ID. Returns the number actually removed.

      Parameters

      • key: string
      • ids: string[]

      Returns Promise<number>

    • XTRIM - trim a stream to (approximately) threshold entries ('MAXLEN') or drop entries older than a given ID ('MINID'). Returns the number of entries removed.

      Parameters

      • key: string
      • strategy: XTrimStrategy
      • threshold: string | number

      Returns Promise<number>

    • XGROUP CREATE - create a consumer group on a stream, starting delivery from id (default '$', i.e. only new entries). Creates the stream first (via MKSTREAM) if it doesn't exist yet.

      Parameters

      • key: string
      • groupName: string
      • id: string = '$'

      Returns Promise<"OK">

    • XREADGROUP - read entries from one or more streams as a named consumer within a consumer group, so entries are tracked in the group's pending-entries list until xack()'d. Pass '>' for an ID to receive only entries never delivered to this group; any other ID re-reads this consumer's already-delivered-but-unacked entries.

      Parameters

      • groupName: string
      • consumerName: string
      • keys: string[]
      • ids: string[]
      • options: XReadOptions = {}

      Returns Promise<StreamReadResult[] | null>

    • XACK - acknowledge that a consumer group has finished processing the given entry IDs.

      Parameters

      • key: string
      • groupName: string
      • ids: string[]

      Returns Promise<number>

    • EVAL - run a Lua script server-side, atomically. keys are passed as Redis's KEYS[1..N] (and count toward the numkeys argument), args as ARGV[1..N]. Prefer evalsha() once a script has been cached (via scriptLoad() or a prior eval()) to avoid resending the source on every call.

      Type Parameters

      • T = unknown

      Parameters

      • script: string
      • keys: string[] = []
      • args: (string | number)[] = []

      Returns Promise<T>

    • EVALSHA - run a previously cached Lua script by its SHA1 digest (see scriptLoad()), avoiding the cost of resending the script body. Redis replies with a NOSCRIPT error (surfaced here as a DatabaseError) if the script isn't cached on the server.

      Type Parameters

      • T = unknown

      Parameters

      • sha1: string
      • keys: string[] = []
      • args: (string | number)[] = []

      Returns Promise<T>

    • SCRIPT LOAD - cache a Lua script on the server without executing it, returning its SHA1 digest for later evalsha() calls.

      Parameters

      • script: string

      Returns Promise<string>

    • PFADD - add elements to a HyperLogLog. Returns 1 if the estimated cardinality changed, 0 otherwise.

      Parameters

      • key: string
      • ...elements: string[]

      Returns Promise<number>

    • PFCOUNT - the approximate cardinality of one HyperLogLog, or the union of several.

      Parameters

      • ...keys: string[]

      Returns Promise<number>

    • PFMERGE - merge one or more source HyperLogLogs into destKey (created/overwritten as the union).

      Parameters

      • destKey: string
      • ...sourceKeys: string[]

      Returns Promise<"OK">

    • Parameters

      • channel: string
      • message: string

      Returns Promise<number>

    • Parameters

      • channel: string
      • handler: (message: string, channel: string) => void

      Returns Promise<void>

    • Parameters

      • Optionalchannel: string

      Returns Promise<void>

    • PSUBSCRIBE - subscribe to all channels matching a glob-style pattern (e.g. news.*, __keyevent@0__:expired) and invoke handler for each matching message. This is the standard mechanism for consuming Redis keyspace notifications (e.g. subscribing to __keyevent@0__:expired to react to key expirations), where the concrete channel name varies and only a pattern subscription can catch all of them. Shares the same lazily-created subscriber connection as subscribe().

      Parameters

      • pattern: string
      • handler: (message: string, channel: string, pattern: string) => void

      Returns Promise<void>

    • PUNSUBSCRIBE - stop receiving messages for pattern (or every pattern subscription, if omitted). Closes the shared subscriber connection once both the channel and pattern handler sets are empty.

      Parameters

      • Optionalpattern: string

      Returns Promise<void>

    • Queue multiple commands and send them in a single round trip. Unlike multi(), commands are not guaranteed atomic — a failure in one command does not abort the others. Returns the ioredis chainable commander; call .exec() to run it.

      Returns ChainableCommander

    • Queue multiple commands to run atomically (Redis MULTI/EXEC). This is Redis's substitute for cross-key transactions: all queued commands either all run or (if .discard() is called) none do, but there is no rollback of partial effects and no cross-command isolation the way a SQL transaction provides. Returns the ioredis chainable commander; call .exec() to run it.

      Returns ChainableCommander