Redis
Redis support shared by persistence modules.
This module defines a Redis service that can send Redis commands, subscribe
to pub/sub channels, and run Lua scripts. 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.
Signature
declare const make: (...args: [options: { 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 send: <A = unknown>(command: string, ...args: readonly Array<string>) => Effect<A, RedisError>; readonly subscribe: (channel: string) => Effect<Dequeue<RedisMessage, RedisError>, never, Scope>;}, never, never>Errors
RedisError
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
RedisMessage interface
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 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);}