Connecting
Build the layer that connects to your server on Node.js, Bun or Upstash.
A runtime layer opens the connection and provides Redis and the services next to it. Pick the layer for the runtime your code runs on.
Example (Reading Connection Settings From Config)
import { Config } from "effect";
import { RedisNode } from "@effect-kit/redis/node";
const settings = Config.all({ url: Config.String("REDIS_URL") });
export const RedisLive = RedisNode.layerConfig(settings);layer takes the settings directly and layerConfig takes an Effect Config of them. The Upstash layer includes Effect's FetchHttpClient. To use your own HttpClient, call RedisUpstash.layerWithHttpClient.
Upstash has fewer services
RedisUpstash provides Redis and UpstashEvents. It does not provide RedisSessions, so there
is no WATCH, no blocking commands and no tracking over HTTP. See
Upstash.
Choosing a URL or an endpoint
Pass exactly one of url or endpoint. Passing both or neither fails with a RedisConfigError.
urlis aredis://orrediss://string. The path can hold a database number, as inredis://localhost:6379/2. The URL cannot have a query string or hash.endpointis{ host, port?, tls? }for TCP,{ path }for a Unix socket, or{ url, tls? }. The port defaults to6379.
Example (Connecting With TLS or a Unix Socket)
import { } from "@effect-kit/redis/node";
// Verified TLS: rediss:// verifies the server certificate
export const = .({ : "rediss://cache.example.com:6380" });
// TLS options on an endpoint
export const = .({
: { : "cache.example.com", : 6380, : { : "cache.example.com" } },
});
// Unix socket
export const = .({ : { : "/var/run/redis/redis.sock" } });A redis: URL combined with tls is a configuration error. Use rediss: for TLS URLs. A rediss: URL verifies the server certificate. To turn that off, pass endpoint: { url, tls: { rejectUnauthorized: false } }.
Common options
These options sit next to url or endpoint on RedisNode.layer and RedisBun.layer. The full list is in Configuration.
Prop
Type
Passing credentials
credentials takes Redacted values. A plain string is a type error. Credentials can also be part of the URL, but not both.
Example (Reading a Password From Config)
import { } from "effect";
import { } from "@effect-kit/redis/node";
export const = .(
.({
: .("REDIS_URL"),
: .({ : .("REDIS_PASSWORD") }),
}),
);