Node.js
Connect to Redis from Node.js over TCP, TLS or a Unix socket with RedisNode.
RedisNode builds layers on node:net and node:tls. It needs Node.js 24.22.0 or later (engines.node is >=24.22.0) and supports every feature of the package.
Example (Creating the Node.js Layer)
import { } from "effect";
import { } from "@effect-kit/redis";
import { } from "@effect-kit/redis/node";
const = .({ : "redis://localhost:6379" });
const = .(function* () {
const = yield* ;
return yield* .();
});
export const = .(.());Creating the layer
RedisNode has six constructors. The Config variants take an Effect Config of the same input.
| Constructor | Builds a layer for |
|---|---|
RedisNode.layer, RedisNode.layerConfig | One standalone server |
RedisNode.layerCluster, RedisNode.layerClusterConfig | A cluster |
RedisNode.layerSentinel, RedisNode.layerSentinelConfig | A Sentinel deployment |
The layer export is the transport
layer exported from @effect-kit/redis/node is the transport, not a client. Build clients with
RedisNode.layer(...).
Provided services
RedisNode.layer provides the full set of services for a standalone server.
Example (The Services a Node.js Layer Provides)
import type { } from "effect";
import { } from "@effect-kit/redis/node";
const = .({ : "redis://localhost:6379" });
type Provided = .<typeof >;RedisTracking, RedisCache, RedisSearch and RedisMonitor are not in the set. You add them yourself.
Transport options
The transport opens one TCP, TLS or Unix socket per connection.
- TCP:
url: "redis://host:6379"orendpoint: { host, port }. - TLS:
url: "rediss://host:6380", orendpointwithtls. Arediss:URL verifies the certificate. - Unix socket:
endpoint: { path: "/var/run/redis/redis.sock" }. Cluster and Sentinel need TCP endpoints.
Prop
Type
Example (Connecting With a Client Certificate)
import { } from "effect";
import { } from "@effect-kit/redis/node";
export const = .(
.({
: .({
: .("REDIS_HOST"),
: .("REDIS_PORT"),
: .({
: .("REDIS_CA"),
: .("REDIS_CERT"),
: .("REDIS_KEY"),
}),
}),
}),
);Tested version
The package is tested on Node.js 24.22.0, against the servers listed in Compatibility.