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.
Constructors
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
unstableError 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
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>;}Options for the pool of connections behind Redis.reserve.
Details
maxConnections: maximum number of reserved connections, default10. Furtherreservecalls wait for a connection to be released.minConnections: connections kept open while idle, default0.idleTimeout: how long a connection aboveminConnectionsstays idle before it is closed, default 60 seconds.acquireTimeout: how longreservewaits for a connection before failing with aRedisError. Unbounded by default.
Signature
interface PoolOptions { readonly acquireTimeout?: Input; readonly idleTimeout?: Input; readonly maxConnections?: number; readonly minConnections?: number;}A message received from a Redis pub/sub channel.
Signature
interface RedisMessage { readonly channel: string; readonly message: string;}Scripting
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;}>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
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);}