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.
index.ts
“./realtime.js” (namespace export)
Re-exports all named exports from the “./realtime.js” module.
Signature
export * from "./realtime.js";
“./redis.js” (namespace export)
Re-exports all named exports from the “./redis.js” module.
Signature
export * from "./redis.js";
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}` }>;
}>;
realtime.ts
RedisAgentStateAdapter (type alias)
Signature
type RedisAgentStateAdapter<Options extends RedisOptions = RedisOptions> = ProviderAdapter<
typeof agentState,
"redis-agent-state",
RedisConnection<Options>,
ProviderBehavior<RedisBehavior<Options>>
>;
RedisRealtimeAdapter (type alias)
Signature
type RedisRealtimeAdapter<Options extends RedisOptions = RedisOptions> = ProviderAdapter<
typeof realtime,
"redis-realtime",
RedisConnection<Options>,
ProviderBehavior<RedisBehavior<Options>>
>;
redisAgentState
Signature
declare const redisAgentState: <
const Options extends RedisOptions = RedisOptions<RedisUrlReference<string> | undefined>,
>(
options?: Options,
) => RedisAgentStateAdapter<Options>;
redisRealtime
Signature
declare const redisRealtime: <
const Options extends RedisOptions = RedisOptions<RedisUrlReference<string> | undefined>,
>(
options?: Options,
) => RedisRealtimeAdapter<Options>;
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>;
Since v0.2.0
RedisAdapter (type alias)
Signature
type RedisAdapter<Options extends RedisOptions = RedisOptions> = ProviderAdapter<
typeof cache,
"redis",
RedisConnection<Options>,
ProviderBehavior<RedisBehavior<Options>>
>;
RedisBehavior (type alias)
Signature
type RedisBehavior<Options extends RedisOptions> = Options extends {
readonly connectionTimeoutMs: infer Timeout extends number;
}
? Readonly<{ connectionTimeoutMs: Timeout }>
: Readonly<Record<never, never>>;
RedisConnection (type alias)
Signature
type RedisConnection<Options extends RedisOptions> = Options extends {
readonly url: infer Url extends RedisUrlReference;
}
? Readonly<{ url: Url }>
: Readonly<Record<never, never>>;
RedisOptions (interface)
Signature
export interface RedisOptions<
Url extends RedisUrlReference | undefined = RedisUrlReference | undefined,
> {
readonly url?: Url;
readonly connectionTimeoutMs?: number;
}
RedisUrlReference (type alias)
Signature
type RedisUrlReference<Name extends string = string> = BindingValueRef<
Name,
string,
"secret-string"
>;
assertRedisOptions
Signature
declare const assertRedisOptions: (options: RedisOptions) => void;
redisConnectionContract
Signature
declare const redisConnectionContract: ProviderConnectionContract;
redisIntegration
Signature
declare const redisIntegration: IntegrationReference<"redis">;
redisLocalRecipe
Signature
declare const redisLocalRecipe: ProviderLocalRecipeReference;
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;
}
createRedisAgentStateProvider
Signature
declare const createRedisAgentStateProvider: (
options: RedisAgentStateProviderOptions,
) => AgentStateProvider & { ready(): Promise<void>; close(): Promise<void> };
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;
}
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>;
}
createRedisClient
Creates a protocol client whose next connection attempt replaces a failed native socket.
Signature
declare const createRedisClient: (options: RedisClientOptions) => RedisProtocolClient;
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";
“./client.js” (namespace export)
Re-exports all named exports from the “./client.js” module.
Signature
export * from "./client.js";
“./provider.js” (namespace export)
Re-exports all named exports from the “./provider.js” module.
Signature
export * from "./provider.js";
“./realtime-provider.js” (namespace export)
Re-exports all named exports from the “./realtime-provider.js” module.
Signature
export * from "./realtime-provider.js";
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>;
};
}
>;
}>;
provider.ts
RedisCacheOptions (interface)
Signature
export interface RedisCacheOptions {
readonly url: string;
readonly cacheId: string;
readonly connectionTimeoutMs?: number;
readonly client?: RedisProtocolClient;
}
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>;
};
}
createRedisCacheProvider
Signature
declare const createRedisCacheProvider: (options: RedisCacheOptions) => RedisCacheProvider;
realtime-provider.ts
RedisRealtimeProviderOptions (interface)
Signature
export interface RedisRealtimeProviderOptions {
readonly url: string;
readonly profile: string;
readonly connectionTimeoutMs?: number;
}
createRedisRealtimeProvider
Signature
declare const createRedisRealtimeProvider: (
options: RedisRealtimeProviderOptions,
) => RealtimeProvider & { ready(): Promise<void>; close(): Promise<void> };
state-store.ts
RedisAgentStore (type alias)
Signature
type RedisAgentStore = AgentStateStore & RedisStateWaiter;
RedisRealtimeStore (type alias)
Signature
type RedisRealtimeStore = RealtimeStateStore & RedisStateWaiter;
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;
}
RedisStateWaiter (interface)
Signature
export interface RedisStateWaiter {
waitForChange(
recheck: () => Promise<boolean>,
deadlineMs: number,
signal: AbortSignal,
): Promise<void>;
ready(): Promise<void>;
close(): Promise<void>;
}
createRedisAgentStore
Signature
declare const createRedisAgentStore: (
options: RedisStateStoreOptions<LocalAgentState>,
) => RedisAgentStore;
createRedisRealtimeStore
Signature
declare const createRedisRealtimeStore: (
options: RedisStateStoreOptions<LocalRealtimeState>,
) => RedisRealtimeStore;