Registry / database / effect-redis

effect-redis

JSON →
library0.0.32jsnpmunverified

A modern, type-safe Effect-TS wrapper for the official `redis` (node-redis) client (v5). Version 0.0.32 — currently pre-1.0 with frequent breaking changes. Key differentiators: resource-safe connection lifecycle via Scope and Layer.scoped, modular services (Core, Pub/Sub, Streams), shared connection across services, tagged error union (RedisConnectionError, RedisCommandError, RedisGeneralError), and a raw escape hatch via use(). Built for Effect-TS ecosystem; requires TypeScript 5+. Release cadence: weekly releases with breaking changes common.

npm install effect-redis
INSTALL
IMPORT
SIG · EFFECT-REDIS
E
effect-redis
databasejavascriptv0.0.32
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Redis
✓ import { Redis } from 'effect-redis'
✗ const { Redis } = require('effect-redis')
ESM-only package; CommonJS require is not supported.
RedisLive
✓ import { RedisLive } from 'effect-redis'
✗ import { RedisLive } from 'effect-redis/RedisLive'
All services are exported from the main module, not subpaths.
RedisConnectionOptionsLive
✓ import { RedisConnectionOptionsLive } from 'effect-redis'
✗ import { RedisConnectionOptionsLive } from 'effect-redis/src/RedisConnectionOptionsLive'
Use named export from root; do not deep-import.
RedisPubSub
✓ import { RedisPubSub } from 'effect-redis'
Import from root; no separate module path.
RedisStream
✓ import { RedisStream } from 'effect-redis'
Streams service is available via same import pattern.

Shows how to connect to Redis, set/get keys, increment a counter, and use pub/sub with Effect-TS layers.

import { Effect, Layer, Stream } from 'effect'; import { RedisConnectionOptionsLive, RedisLive, RedisPubSubLive, Redis, RedisPubSub, } from 'effect-redis'; const program = Effect.gen(function* () { const redis = yield* Redis; const pubsub = yield* RedisPubSub; yield* redis.set('user:42', JSON.stringify({ name: 'Ada' })); const val = yield* redis.get('user:42'); yield* redis.set('counter', '1'); yield* redis.incr('counter'); const subscription = yield* pubsub.subscribe('notifications'); yield* Effect.fork( Stream.runForEach(subscription, (msg) => Effect.log(`Received: ${msg}`) ) ); yield* pubsub.publish('notifications', 'Hello world!'); }); const RedisLayer = RedisConnectionOptionsLive({ url: process.env.REDIS_URL ?? 'redis://localhost:6379', }).pipe( Layer.provideMerge(RedisLive), Layer.provideMerge(RedisPubSubLive) ); Effect.runPromise(program.pipe(Effect.provide(RedisLayer)));
Debug
Known issues
breakingVersion 0.x is pre-release; breaking changes can occur at any minor/patch bump.
fix
Pin to exact version and test upgrades carefully.
affects: <1.0.0
deprecatedThe 'use()' method provides access to the raw node-redis client but may change or be removed in future versions.
fix
Avoid relying on raw client if possible; prefer Effect-Redis services.
affects: >=0.0.32
gotchaPub/Sub subscriber uses a dedicated connection; do not send commands other than subscribe/unsubscribe on the same client.
fix
Use RedisPubSub service for pub/sub operations; do not mix with core Redis service on the same client.
affects: >=0.0.0
gotchaRedisConnectionOptionsLive must be provided before other layers; otherwise connection defaults may not apply.
fix
Always provide RedisConnectionOptionsLive as the first layer.
affects: >=0.0.0
gotchaError handling: The package uses tagged errors; ensure you catch 'RedisConnectionError', 'RedisCommandError', or 'RedisGeneralError'.
fix
Use Effect.catchTags to handle specific error types.
affects: >=0.0.0
Errors
Common errors & fixes
Module not found: Can't resolve 'effect'
Peer dependency 'effect' not installed.
fix
Install effect: npm install effect
TypeError: (0 , effect_redis__WEBPACK_IMPORTED_MODULE_1__.Redis) is not a function
Importing Redis incorrectly as a default import or calling it as a function.
fix
Use the correct named import: import { Redis } from 'effect-redis' (Redis is a service tag, not a constructor).
Uncaught (in promise) EffectUnknown: Layer { _tag: 'Layer', ... }
Layer not provided to the Effect before running.
fix
Use Effect.provide(layer) or Effect.runPromise(program.pipe(Effect.provide(layer)))
Error: The client is closed
Connection layer (RedisConnectionLive) not provided or improperly scoped.
fix
Ensure RedisConnectionOptionsLive and RedisLive (or RedisPubSubLive/RedisStreamLive) are composed into a layer and provided to the Effect.
Upgrade
Version history
0.0.32latest on npm
Audit
Dependencies
redisrequiredPeer dependency for the underlying Redis client; version ^5.1.0 required.
typescriptoptionalPeer dependency for type safety; version ^5 required.
Agent activity
10 hits · last 30 days
node
8
Resources
effect-redis — npm install effect-redis · libregistry