Skip to content
RELKIT
Esc
↑↓navigate↵open⌘Jpreview
On this page

Redis API

Generated public TypeScript reference for @relkit/redis.

For configuration and examples, read integrations, local docker, providers.

For a complete workflow, follow cache product prices.

Public imports

  • @relkit/redis — 14 exports
  • @relkit/redis/runtime — 11 exports
  • @relkit/redis/local-recipe — 1 exports

All exported APIs

Names link to their complete contracts. Re-exports share their original contract; legacy exports keep their separate identity. Examples link to the API’s inline sample, a maintained repository usage, or the shared module walkthrough.

API Kind Import from Example
assertRedisOptions Value @relkit/redis Module example
createRedisAgentStateProvider Value @relkit/redis/runtime Source example
createRedisCacheProvider Value @relkit/redis/runtime Source example
createRedisClient Value @relkit/redis/runtime Source example
createRedisRealtimeProvider Value @relkit/redis/runtime Source example
localRecipe Value @relkit/redis/local-recipe Source example
redis Value @relkit/redis API example
RedisAdapter Type @relkit/redis Module example
redisAgentState Value @relkit/redis Source example
RedisAgentStateAdapter Type @relkit/redis Module example
RedisAgentStateProviderOptions Type @relkit/redis/runtime Module example
RedisBehavior Type @relkit/redis Module example
RedisCacheOptions Type @relkit/redis/runtime Module example
RedisCacheProvider Type @relkit/redis/runtime Module example
RedisClientOptions Type @relkit/redis/runtime Module example
RedisConnection Type @relkit/redis Module example
redisConnectionContract Value @relkit/redis Module example
redisIntegration Value @relkit/redis Module example
redisLocalRecipe Value @relkit/redis Module example
RedisOptions Type @relkit/redis Module example
RedisProtocolClient Type @relkit/redis/runtime Source example
redisRealtime Value @relkit/redis Source example
RedisRealtimeAdapter Type @relkit/redis Module example
RedisRealtimeProviderOptions Type @relkit/redis/runtime Module example
RedisUrlReference Type @relkit/redis Module example
runtimeIntegration Value @relkit/redis/runtime Module example

index.ts

“./realtime.js” (namespace export)

Re-exports all named exports from the “./realtime.js” module.

Signature

export * from "./realtime.js";

Source

“./redis.js” (namespace export)

Re-exports all named exports from the “./redis.js” module.

Signature

export * from "./redis.js";

Source

index.ts

localRecipe

Signature

declare const localRecipe: Readonly<{
  kind: "local-service-recipe";
  protocolVersion: 1;
  integrationId: "redis";
  recipeId: "redis-docker";
  recipeVersion: 1;
  materializerId: "docker";
  image: "redis:7.4.2-alpine@sha256:02419de7eddf55aa5bcf49efb74e88fa8d931b4d77c07eff8a6b2144472b6952";
  command: ReadonlyArray<string>;
  ports: Readonly<{ redis: 6379 }>;
  volume: Readonly<{ mountPath: "/data" }>;
  health: Readonly<{
    command: ReadonlyArray<string>;
    intervalMs: 250;
    timeoutMs: 2000;
    retries: 40;
  }>;
  outputs: ({
    ports,
  }: LocalServiceRecipeOutputContext) => Readonly<{ url: `redis://127.0.0.1:${number}` }>;
}>;

Source

realtime.ts

RedisAgentStateAdapter (type alias)

Signature

type RedisAgentStateAdapter<Options extends RedisOptions = RedisOptions> = ProviderAdapter<
  typeof agentState,
  "redis-agent-state",
  RedisConnection<Options>,
  ProviderBehavior<RedisBehavior<Options>>
>;

Source

RedisRealtimeAdapter (type alias)

Signature

type RedisRealtimeAdapter<Options extends RedisOptions = RedisOptions> = ProviderAdapter<
  typeof realtime,
  "redis-realtime",
  RedisConnection<Options>,
  ProviderBehavior<RedisBehavior<Options>>
>;

Source

redisAgentState

Signature

declare const redisAgentState: <
  const Options extends RedisOptions = RedisOptions<RedisUrlReference<string> | undefined>,
>(
  options?: Options,
) => RedisAgentStateAdapter<Options>;

Source

redisRealtime

Signature

declare const redisRealtime: <
  const Options extends RedisOptions = RedisOptions<RedisUrlReference<string> | undefined>,
>(
  options?: Options,
) => RedisRealtimeAdapter<Options>;

Source

redis.ts

redis

Defines a Redis-compatible cache adapter. Omit url for a deferred local or infrastructure source.

Example

import { env } from "@relkit/app/config";
import { redis } from "@relkit/redis";
const cache = redis({ url: env.secret("CACHE_URL") });

Signature

declare const redis: <
  const Options extends RedisOptions = RedisOptions<RedisUrlReference<string> | undefined>,
>(
  options?: Options,
) => RedisAdapter<Options>;

Source

Since v0.2.0

RedisAdapter (type alias)

Signature

type RedisAdapter<Options extends RedisOptions = RedisOptions> = ProviderAdapter<
  typeof cache,
  "redis",
  RedisConnection<Options>,
  ProviderBehavior<RedisBehavior<Options>>
>;

Source

RedisBehavior (type alias)

Signature

type RedisBehavior<Options extends RedisOptions> = Options extends {
  readonly connectionTimeoutMs: infer Timeout extends number;
}
  ? Readonly<{ connectionTimeoutMs: Timeout }>
  : Readonly<Record<never, never>>;

Source

RedisConnection (type alias)

Signature

type RedisConnection<Options extends RedisOptions> = Options extends {
  readonly url: infer Url extends RedisUrlReference;
}
  ? Readonly<{ url: Url }>
  : Readonly<Record<never, never>>;

Source

RedisOptions (interface)

Signature

export interface RedisOptions<
  Url extends RedisUrlReference | undefined = RedisUrlReference | undefined,
> {
  readonly url?: Url;
  readonly connectionTimeoutMs?: number;
}

Source

RedisUrlReference (type alias)

Signature

type RedisUrlReference<Name extends string = string> = BindingValueRef<
  Name,
  string,
  "secret-string"
>;

Source

assertRedisOptions

Signature

declare const assertRedisOptions: (options: RedisOptions) => void;

Source

redisConnectionContract

Signature

declare const redisConnectionContract: ProviderConnectionContract;

Source

redisIntegration

Signature

declare const redisIntegration: IntegrationReference<"redis">;

Source

redisLocalRecipe

Signature

declare const redisLocalRecipe: ProviderLocalRecipeReference;

Source

agent-state-provider.ts

Binds the native Redis transaction adapter to the generic agent-state provider contract.

RedisAgentStateProviderOptions (interface)

Signature

export interface RedisAgentStateProviderOptions {
  readonly url: string;
  readonly profile: string;
  readonly connectionTimeoutMs?: number;
}

Source

createRedisAgentStateProvider

Signature

declare const createRedisAgentStateProvider: (
  options: RedisAgentStateProviderOptions,
) => AgentStateProvider & { ready(): Promise<void>; close(): Promise<void> };

Source

client.ts

Owns the native Redis connection; a later operation can reconnect without replaying failed commands.

RedisClientOptions (interface)

Owns the native Redis connection; a later operation can reconnect without replaying failed commands.

Signature

export interface RedisClientOptions {
  readonly url: string;
  readonly connectionTimeoutMs?: number;
}

Source

RedisProtocolClient (interface)

Signature

export interface RedisProtocolClient {
  readonly connected: boolean;
  connect(): Promise<void>;
  close(): void;
  ping(): Promise<boolean>;
  get(key: string): Promise<string | null>;
  set(key: string, value: string, ttlMs?: number): Promise<void>;
  delete(key: string): Promise<number>;
  has(key: string): Promise<boolean>;
  increment(key: string, amount?: number): Promise<number>;
  scan(
    cursor: string,
    pattern: string,
    count: number,
  ): Promise<readonly [string, readonly string[]]>;
  type(key: string): Promise<string>;
  ttl(key: string): Promise<number>;
  command(command: string, args: readonly string[]): Promise<unknown>;
}

Source

createRedisClient

Creates a protocol client whose next connection attempt replaces a failed native socket.

Signature

declare const createRedisClient: (options: RedisClientOptions) => RedisProtocolClient;

Source

index.ts

“./agent-state-provider.js” (namespace export)

Re-exports all named exports from the “./agent-state-provider.js” module.

Signature

export * from "./agent-state-provider.js";

Source

“./client.js” (namespace export)

Re-exports all named exports from the “./client.js” module.

Signature

export * from "./client.js";

Source

“./provider.js” (namespace export)

Re-exports all named exports from the “./provider.js” module.

Signature

export * from "./provider.js";

Source

“./realtime-provider.js” (namespace export)

Re-exports all named exports from the “./realtime-provider.js” module.

Signature

export * from "./realtime-provider.js";

Source

runtimeIntegration

Signature

declare const runtimeIntegration: Readonly<{
  kind: "runtime-integration";
  integrationId: "redis";
  registrations: ReadonlyArray<
    | {
        capability: string;
        adapterId: string;
        protocolVersion: number;
        create: ({ profile, connection, behavior }: RuntimeProviderContext) => {
          value: RedisCacheProvider;
          ready: () => Promise<void>;
          release: () => Promise<void>;
        };
      }
    | {
        capability: string;
        adapterId: string;
        protocolVersion: number;
        create: ({ profile, connection, behavior }: RuntimeProviderContext) => {
          value: RealtimeProvider & { ready(): Promise<void>; close(): Promise<void> };
          ready: () => Promise<void>;
          release: () => Promise<void>;
        };
      }
    | {
        capability: string;
        adapterId: string;
        protocolVersion: number;
        create: ({ profile, connection, behavior }: RuntimeProviderContext) => {
          value: AgentStateProvider & { ready(): Promise<void>; close(): Promise<void> };
          ready: () => Promise<void>;
          release: () => Promise<void>;
        };
      }
  >;
}>;

Source

provider.ts

RedisCacheOptions (interface)

Signature

export interface RedisCacheOptions {
  readonly url: string;
  readonly cacheId: string;
  readonly connectionTimeoutMs?: number;
  readonly client?: RedisProtocolClient;
}

Source

RedisCacheProvider (interface)

Signature

export interface RedisCacheProvider extends CacheProvider {
  readonly ready: () => Promise<void>;
  readonly close: () => Promise<void>;
  readonly inspector: {
    readonly scan: (request: {
      readonly search?: string;
      readonly cursor?: string;
      readonly limit: number;
      readonly signal: AbortSignal;
    }) => Promise<{ readonly items: readonly unknown[]; readonly nextCursor?: string }>;
    readonly value: (request: {
      readonly key: string;
      readonly limit: number;
      readonly signal: AbortSignal;
    }) => Promise<unknown | undefined>;
  };
}

Source

createRedisCacheProvider

Signature

declare const createRedisCacheProvider: (options: RedisCacheOptions) => RedisCacheProvider;

Source

realtime-provider.ts

RedisRealtimeProviderOptions (interface)

Signature

export interface RedisRealtimeProviderOptions {
  readonly url: string;
  readonly profile: string;
  readonly connectionTimeoutMs?: number;
}

Source

createRedisRealtimeProvider

Signature

declare const createRedisRealtimeProvider: (
  options: RedisRealtimeProviderOptions,
) => RealtimeProvider & { ready(): Promise<void>; close(): Promise<void> };

Source

state-store.ts

RedisAgentStore (type alias)

Signature

type RedisAgentStore = AgentStateStore & RedisStateWaiter;

Source

RedisRealtimeStore (type alias)

Signature

type RedisRealtimeStore = RealtimeStateStore & RedisStateWaiter;

Source

RedisStateStoreOptions (interface)

Signature

export interface RedisStateStoreOptions<State> {
  readonly url: string;
  readonly key: string;
  readonly empty: () => State;
  readonly valid: (state: unknown) => state is State;
  readonly connectionTimeoutMs?: number;
}

Source

RedisStateWaiter (interface)

Signature

export interface RedisStateWaiter {
  waitForChange(
    recheck: () => Promise<boolean>,
    deadlineMs: number,
    signal: AbortSignal,
  ): Promise<void>;
  ready(): Promise<void>;
  close(): Promise<void>;
}

Source

createRedisAgentStore

Signature

declare const createRedisAgentStore: (
  options: RedisStateStoreOptions<LocalAgentState>,
) => RedisAgentStore;

Source

createRedisRealtimeStore

Signature

declare const createRedisRealtimeStore: (
  options: RedisStateStoreOptions<LocalRealtimeState>,
) => RedisRealtimeStore;

Source