class RedisStore
implements CacheStore
Since 0.1.0

Redis-backed cache store implementation.

Values are JSON-serialized before storage so that arbitrary types can be cached. The prefix is applied at construction time and used exclusively by clear() to scope the SCAN+DEL to this instance's keys.

Constructors

RedisStore(
prefix: string,
options?: { url?: string | undefined; client?: IRedisClient | undefined; }
)
Parameters
prefix: string

Key prefix for scoping clear() to this instance's keys. An empty prefix would scan * in clear() — acceptable only for single- tenant Redis deployments.

optional
options: { url?: string | undefined; client?: IRedisClient | undefined; }

Redis connection and client options

Methods

clear(): Promise<void>

Remove all entries scoped to this backend's prefix.

The prefix is provided at construction time (not per-call), so each backend can scope the clear appropriately:

  • Redis: SCAN MATCH ${prefix}* + batch DEL
  • Memory: empty the internal map (each plugin instance owns its own map, so it naturally holds only this prefix's keys)
connect(): Promise<void>

Establish the backend connection (if applicable).

delete(key: string): Promise<boolean>

Delete a value. The key is already-prefixed by CacheService.

disconnect(): Promise<void>

Gracefully disconnect.

get<T>(key: string): Promise<T | null>

Read a value. The key is already-prefixed by CacheService.

has(key: string): Promise<boolean>

Check existence. The key is already-prefixed by CacheService.

Since 0.5.0
isHealthy(): Promise<boolean>

Probes Redis with a typed ping() (M90b). false after disconnect — a store with no client cannot answer — and otherwise true only when the server answers, a rejection being unreachability.

The plugin caches and bounds this probe; this method is the raw per-call question.

isReady(): boolean

Reports whether the backend is ready for operations.

set<T>(
key: string,
value: T,
ttlSeconds?: number
): Promise<void>

Write a value. The key is already-prefixed by CacheService.

Usage

import { RedisStore } from "cache-plugin/src/index.ts";