Skip to content
// EFFECT DAYS 2026

Redis unstable

Redis support shared by persistence modules.

This module defines a Redis service that can send Redis commands, subscribe to pub/sub channels, run Lua scripts, and reserve a dedicated connection from a pool. It does not create a Redis client itself; callers provide the client-specific operations. The module also provides helpers for describing Lua scripts, loading them once, and running them later by their cached Redis id.

8 exports Since v4.0.0 Source

Constructors

make

unstable
Since v4.0.0

Creates a Redis service from raw command and subscription operations.

Details

Lua scripts are loaded through SCRIPT LOAD, cached, and then invoked with EVALSHA.

connect opens the dedicated connections behind reserve. Its close must fail any command still in flight on that connection. Connections are pooled according to pool, and closing the scope closes every connection, including reserved ones with a command in flight.

Signature

declare const make: (...args: [options: {
readonly connect: Effect<{
readonly close: Effect<void>;
readonly send: <A = unknown>(command: string, ...args: readonly Array<string>) => Effect<A, RedisError>;
}, RedisError>;
readonly pool?: PoolOptions;
readonly send: <A = unknown>(command: string, ...args: readonly Array<string>) => Effect<A, RedisError>;
readonly subscribe: (channel: string, onMessage: (message: RedisMessage) => void) => Effect<Effect<void, RedisError, never>, RedisError, Scope>;
}]) => Effect<{
readonly eval: <Config extends {
readonly params: readonly Array<unknown>;
readonly result: unknown;
}>(script: Script<Config>) => (...params: Config["params"]) => Effect<Config["result"], RedisError>;
readonly reserve: Effect<Connection, RedisError, Scope>;
readonly send: <A = unknown>(command: string, ...args: readonly Array<string>) => Effect<A, RedisError>;
readonly subscribe: (channel: string) => Effect<Dequeue<RedisMessage, RedisError>, never, Scope>;
}, never, Scope>

Errors

RedisError

unstable
Since v4.0.0

Error raised by Redis command or script execution.

Signature

declare class RedisError extends {
readonly _tag: "RedisError";
readonly cause: unknown;
} & YieldableError<this> {
constructor(...args: [props: {
readonly _tag?: "RedisError";
readonly cause: unknown;
}, options?: MakeOptions]);
readonly "~effect/persistence/Redis/RedisError": "~effect/persistence/Redis/RedisError";
}

Models

Connection

interface unstable
Since v4.0.7

A dedicated Redis connection obtained from Redis.reserve.

Details

eval loads scripts through the shared connection and runs EVALSHA on this connection.

Signature

interface Connection {
readonly eval: <Config extends {
readonly params: readonly Array<unknown>;
readonly result: unknown;
}>(script: Script<Config>) => (...params: Config["params"]) => Effect<Config["result"], RedisError>;
readonly send: <A = unknown>(command: string, ...args: readonly Array<string>) => Effect<A, RedisError>;
}

PoolOptions

interface unstable
Since v4.0.7

Options for the pool of connections behind Redis.reserve.

Details

  • maxConnections: maximum number of reserved connections, default 10. Further reserve calls wait for a connection to be released.
  • minConnections: connections kept open while idle, default 0.
  • idleTimeout: how long a connection above minConnections stays idle before it is closed, default 60 seconds.
  • acquireTimeout: how long reserve waits for a connection before failing with a RedisError. Unbounded by default.

Signature

interface PoolOptions {
readonly acquireTimeout?: Input;
readonly idleTimeout?: Input;
readonly maxConnections?: number;
readonly minConnections?: number;
}

RedisMessage

interface unstable
Since v4.0.0

A message received from a Redis pub/sub channel.

Signature

interface RedisMessage {
readonly channel: string;
readonly message: string;
}

Scripting

script

unstable
Since v4.0.0

Constructs a typed Redis Lua script descriptor.

Details

The result type defaults to void and can be refined with withReturnType.

Signature

declare function script<Params extends readonly Array<any>>(f: (...params: Params) => readonly Array<unknown>, options: {
readonly lua: string;
readonly numberOfKeys: number | (...params: Params) => number;
}): Script<{
params: Params;
result: void;
}>

Script

interface unstable
Since v4.0.0

Typed descriptor for a Redis Lua script.

Details

It defines the Lua source, parameter-to-argument mapping, Redis key count, and result type used by Redis.eval.

Signature

interface Script<Config extends {
readonly params: ReadonlyArray<unknown>;
readonly result: unknown;
}> {
readonly "~effect/persistence/Redis/Script": {
readonly params: Config["params"];
readonly result: Config["result"];
};
readonly lua: string;
readonly numberOfKeys: (...params: Config["params"]) => number;
readonly params: (...params: Config["params"]) => readonly Array<unknown>;
withReturnType<Result>(): Script<{
params: Config["params"];
result: Result;
}>;
}

Services

Redis

unstable
Since v4.0.0

Service for sending Redis commands, subscribing to channels, and evaluating cached Lua scripts.

Signature

declare class Redis extends Shape<"effect/persistence/Redis", {
readonly eval: <Config extends {
readonly params: readonly Array<unknown>;
readonly result: unknown;
}>(script: Script<Config>) => (...params: Config["params"]) => Effect<Config["result"], RedisError>;
readonly reserve: Effect<Connection, RedisError, Scope>;
readonly send: <A = unknown>(command: string, ...args: readonly Array<string>) => Effect<A, RedisError>;
readonly subscribe: (channel: string) => Effect<Dequeue<RedisMessage, RedisError>, never, Scope>;
}, this> {
constructor(_: never);
}