import * as Cause from "../Cause.ts"; import * as Context from "../Context.ts"; import * as Duration from "../Duration.ts"; import * as Effect from "../Effect.ts"; import * as Queue from "../Queue.ts"; import * as Schema from "../Schema.ts"; import * as Scope from "../Scope.ts"; /** * A message received from a Redis pub/sub channel. * * @stability unstable * @category models * @since 4.0.0 */ export interface RedisMessage { readonly channel: string; readonly message: string; } declare const Redis_base: Context.ServiceClass(command: string, ...args: ReadonlyArray) => Effect.Effect; /** * Subscribes to a Redis pub/sub channel for the lifetime of the current * scope. Node and Deno subscribers reconnect and re-subscribe after an * interruption, so messages published during recovery appear as delivery * gaps. Bun subscribers do not reconnect: a dropped connection fails the * dequeue, and the caller must subscribe again. */ readonly subscribe: (channel: string) => Effect.Effect, never, Scope.Scope>; readonly eval: ; readonly result: unknown; }>(script: Script) => (...params: Config["params"]) => Effect.Effect; /** * Reserves a pooled connection that no other caller shares for the lifetime * of the current scope. * * Use it for blocking commands such as `XREAD BLOCK`, `XREADGROUP BLOCK`, * `BLPOP`, `BRPOP`, `BLMOVE`, `BLMPOP` and `WAIT`, which would otherwise * hold up every command queued behind them on the shared connection. * * When the scope closes, the connection returns to the pool. If a command on * it failed, was interrupted, or is still running, the connection is closed * instead, because Redis may still be processing the command. */ readonly reserve: Effect.Effect; }>; /** * Service for sending Redis commands, subscribing to channels, and evaluating * cached Lua scripts. * * @stability unstable * @category services * @since 4.0.0 */ export declare class Redis extends Redis_base { } /** * A dedicated Redis connection obtained from `Redis.reserve`. * * **Details** * * `eval` loads scripts through the shared connection and runs `EVALSHA` on * this connection. * * @stability unstable * @category models * @since 4.0.7 */ export interface Connection { readonly send: Redis["Service"]["send"]; readonly eval: Redis["Service"]["eval"]; } /** * 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. * * @stability unstable * @category models * @since 4.0.7 */ export interface PoolOptions { readonly maxConnections?: number | undefined; readonly minConnections?: number | undefined; readonly idleTimeout?: Duration.Input | undefined; readonly acquireTimeout?: Duration.Input | undefined; } /** * 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. * * @stability unstable * @category constructors * @since 4.0.0 */ export declare const make: (options: { readonly send: (command: string, ...args: ReadonlyArray) => Effect.Effect; readonly subscribe: (channel: string, onMessage: (message: RedisMessage) => void) => Effect.Effect, RedisError, Scope.Scope>; readonly connect: Effect.Effect<{ readonly send: (command: string, ...args: ReadonlyArray) => Effect.Effect; readonly close: Effect.Effect; }, RedisError>; readonly pool?: PoolOptions | undefined; }) => Effect.Effect<{ readonly send: (command: string, ...args: ReadonlyArray) => Effect.Effect; /** * Subscribes to a Redis pub/sub channel for the lifetime of the current * scope. Node and Deno subscribers reconnect and re-subscribe after an * interruption, so messages published during recovery appear as delivery * gaps. Bun subscribers do not reconnect: a dropped connection fails the * dequeue, and the caller must subscribe again. */ readonly subscribe: (channel: string) => Effect.Effect, never, Scope.Scope>; readonly eval: ; readonly result: unknown; }>(script: Script) => (...params: Config["params"]) => Effect.Effect; /** * Reserves a pooled connection that no other caller shares for the lifetime * of the current scope. * * Use it for blocking commands such as `XREAD BLOCK`, `XREADGROUP BLOCK`, * `BLPOP`, `BRPOP`, `BLMOVE`, `BLMPOP` and `WAIT`, which would otherwise * hold up every command queued behind them on the shared connection. * * When the scope closes, the connection returns to the pool. If a command on * it failed, was interrupted, or is still running, the connection is closed * instead, because Redis may still be processing the command. */ readonly reserve: Effect.Effect; }, never, Scope.Scope>; type ErrorTypeId = "~effect/persistence/Redis/RedisError"; declare const ErrorTypeId: ErrorTypeId; declare const RedisError_base: Schema.Class; readonly cause: Schema.Defect; }>, Cause.YieldableError>; /** * Error raised by Redis command or script execution. * * @stability unstable * @category errors * @since 4.0.0 */ export declare class RedisError extends RedisError_base { /** * Marks this value as a Redis persistence error for runtime guards. * * @stability unstable * @since 4.0.0 */ readonly [ErrorTypeId]: ErrorTypeId; } type ScriptTypeId = "~effect/persistence/Redis/Script"; declare const ScriptTypeId: ScriptTypeId; /** * 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`. * * @stability unstable * @category scripting * @since 4.0.0 */ export interface Script; readonly result: unknown; }> { readonly [ScriptTypeId]: { readonly params: Config["params"]; readonly result: Config["result"]; }; readonly lua: string; readonly params: (...params: Config["params"]) => ReadonlyArray; readonly numberOfKeys: (...params: Config["params"]) => number; /** * Set the return type of the script. */ withReturnType(): Script<{ params: Config["params"]; result: Result; }>; } /** * Constructs a typed Redis Lua script descriptor. * * **Details** * * The result type defaults to `void` and can be refined with * `withReturnType`. * * @stability unstable * @category scripting * @since 4.0.0 */ export declare const script: >(f: (...params: Params) => ReadonlyArray, options: { readonly lua: string; readonly numberOfKeys: number | ((...params: Params) => number); }) => Script<{ params: Params; result: void; }>; export {}; //# sourceMappingURL=Redis.d.ts.map