Registry / messaging / redis-eventemitter

redis-eventemitter

JSON →
library2.0.1jsnpmunverified

Redis pub/sub using a simple event emitter. Current stable version 2.0.1. Wraps the event emitter pattern around Redis pub/sub, allowing Node.js developers to use familiar .on() and .emit() methods for pub/sub messaging. Supports pattern subscriptions with wildcards, prefixes for namespacing channels, and custom Redis clients. Differentiates by providing a high-level API that abstracts Redis pub/sub details, though it is limited in flexibility and has known gotchas with error handling and prefix behavior.

npm install redis-eventemitter
INSTALL
IMPORT
SIG · REDIS-EVENTEMITTER
R
redis-eventemitter
messagingjavascriptv2.0.1
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.

default
import redisEventEmitter from 'redis-eventemitter';
const redis = require('redis-eventemitter');
Package exports a factory function as default export. ESM import is default.
redisEventEmitter
const redis = require('redis-eventemitter'); const pubsub = redis({ url: '...' });
const redis = require('redis-eventemitter'); const pubsub = new redis();
CommonJS usage: the factory is the default export. Do not use 'new'.
.on
pubsub.on('error', console.error); pubsub.on('*:newuser', (channel, msg) => {});
pubsub.on('message', callback);
Use wildcard patterns; raw Redis channel event name is not exposed. 'error' special case: cannot listen on 'error' channel for messages.
.emit
pubsub.emit('myevent', { data: 1 });
pubsub.emit('myevent'); pubsub.emit('myevent', 'string');
Messages are JSON.stringify'd before publishing. For non-JSON values, unexpected behavior may occur.

Creates a redis pub/sub emitter, subscribes to all events under 'myapp:', emits an event, then cleans up.

import redisEventEmitter from 'redis-eventemitter'; const pubsub = redisEventEmitter({ url: 'redis://localhost:6379', prefix: 'myapp:' }); pubsub.on('*:event', (channel, message) => { console.log(`Received on ${channel}:`, message); }); pubsub.emit('user:event', { id: 1, name: 'Alice' }); setTimeout(() => { pubsub.removeAllListeners; pubsub.quit?.(); }, 1000);
Debug
Known issues
gotcha.on('error', ...) intercepts Redis errors and prevents listening on the 'error' channel.
fix
Use a separate error handler; do not rely on .on('error') to receive messages.
affects: *
gotchaPrefix is prepended for emit but stripped from channel in callback. This may cause confusion if using multiple prefixes.
fix
Ensure prefix ends with ':' and be aware that subscribe patterns should not include prefix.
affects: *
breakingVersion 2.x may have changed client initialization. Always pass options object or url.
fix
Check that options are correctly passed; avoid positional arguments.
affects: >=2.0.0
deprecatedPackage may not be actively maintained; consider alternatives like ioredis with built-in pub/sub.
fix
Migrate to a more modern Redis client if possible.
affects: *
Errors
Common errors & fixes
TypeError: redis is not a function
Using 'new redis()' instead of calling the factory function directly.
fix
Replace 'new redis(...)' with 'const pubsub = redis(...)'.
TypeError: pubsub.on is not a function
Not calling the exported factory; the import incorrectly refers to the module itself.
fix
Ensure you import the function and call it with options: 'const pubsub = require('redis-eventemitter')(options)'.
Redis connection error: getaddrinfo ENOTFOUND
Invalid host in Redis URL or options.
fix
Correct the host/port in options.url or host/port fields.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
redisrequiredRequired for underlying Redis pub/sub connectivity
Agent activity
25 hits · last 30 days
node
22
Amazon
1
OpenAI (training)
1
Resources
redis-eventemitter — npm install redis-eventemitter · libregistry