ioredis-eventemitter
Redis pubsub using an event emitter via ioredis Redis client
ioredis is a robust, performance-focused and full-featured Redis client for Node and io.js.
This work based on redis-eventemitter
Install
npm install ioredis-eventemitter
Usage
pub/sub clients must be compatible ioredis
var redis = ; var pubsub = ; // Listen for messages on the *:newuser channelpubsub; // Publish an event "production:myservice:newuser" to the redis pubsubpubsub;
API
.emit(channel, messages...) [publish]
var redis = ;var pubsub = ;pubsub;
.on(pattern, function(channel, messages...) { ... }) [subscribe]
var redis = ;var pubsub = ;pubsub;
.on('error', function(err) { ... }) [error handling]
To be able to handle errors (like when the redis server is down) .on('error', ...)
should be used.
Note that this means that you can't listen for messages on the error
channel.
.removeListener(pattern, listener)
Removes listener.
.removeAllListeners(pattern)
Removes all listeners.
Options
port
Port for the redis server. Defaults to 6379.
host
Host for the redis server. Defaults to 127.0.0.1.
password
Password for the redis server. Defaults to not being set.
prefix
A prefix that is added to the channel name, when publishing events to the redis pubsub. Useful for separating services or environments, e.g. production
, development
, and staging
.
It is also removed when the listeners is invoked.
pub
ioredis compatible Redis client instance used for publish
.
sub
ioredis compatible Redis client instance used for subscribe
.