(options?: IoRedis.RedisOptions | undefined): Layer.Layer<
Redis.Redis | NodeRedis
>Provides Redis and NodeRedis services backed by an ioredis client
created with the supplied options and closed when the layer scope ends.
export const const layer: (
options?: IoRedis.RedisOptions | undefined
) => Layer.Layer<Redis.Redis | NodeRedis>
Provides Redis and NodeRedis services backed by an ioredis client
created with the supplied options and closed when the layer scope ends.
layer = (
options: anyoptions?: import IoRedisIoRedis.type IoRedis.RedisOptions = /*unresolved*/ anyRedisOptions | undefined
): import LayerLayer.interface Layer<in ROut, out E = never, out RIn = never>A Layer describes how to build one or more services for dependency injection.
When to use
Use to model construction of application services for dependency injection,
especially when services have dependencies, can fail during construction, or
need scoped setup and release.
Details
A Layer<ROut, E, RIn> represents ROut as the services this layer
provides, E as the possible errors during layer construction, and RIn as
the services this layer requires as dependencies.
Layer<import RedisRedis.class Redisclass Redis {
key: Identifier;
Service: {
send: <A = unknown>(command: string, ...args: ReadonlyArray<string>) => Effect.Effect<A, RedisError>;
eval: <Config extends { readonly params: ReadonlyArray<unknown>; readonly result: unknown }>(script: Script<Config>) => (...params: Config["params"]) => Effect.Effect<Config["result"], RedisError>;
};
}
Service for sending Redis commands and evaluating cached Lua scripts.
Redis | class NodeRedisclass NodeRedis {
key: Identifier;
Service: {
client: IoRedis.Redis;
use: <A>(f: (client: IoRedis.Redis) => Promise<A>) => Effect.Effect<A, Redis.RedisError>;
};
}
Service tag for the Node Redis integration, exposing the underlying
ioredis client and a use helper that maps client failures to
RedisError.
NodeRedis> => import LayerLayer.const effectContext: <A, E, R>(
effect: Effect<Context.Context<A>, E, R>
) => Layer<A, E, Exclude<R, Scope.Scope>>
Constructs a layer from an effect that produces all services in a Context.
When to use
Use when you need a Layer that effectfully constructs a Context with
multiple services.
Details
This allows you to create a Layer from an effectful computation that
returns multiple services. The Effect is executed in the scope of the
layer.
Example (Creating a layer from an effectful context)
import { Context, Effect, Layer } from "effect"
class Database extends Context.Service<
Database,
{ readonly query: (sql: string) => Effect.Effect<string> }
>()("Database") {}
const layer = Layer.effectContext(
Effect.succeed(Context.make(Database, {
query: (sql: string) => Effect.succeed(`Query: ${sql}`)
}))
)
effectContext(const make: (
options?: any
) => Effect.Effect<
Context.Context<NodeRedis | Redis.Redis>,
never,
Scope.Scope
>
make(options: anyoptions))