Wrapper for easy communication between processes via Redis Pub/Sub.
npm install redis-ps
yarn add redis-ps
You can connect to socket:
new RedisPS('/tmp/redis.sock');
By Redis DSN:
new RedisPS('redis://:authpassword@127.0.0.1:6380/4');
Or by ordinary host and port:
new Redis({
port: 6379, // Redis port, default is 6379
host: '127.0.0.1', // Redis host is '127.0.0.1'
family: 4, // 4 (IPv4) or 6 (IPv6)
password: 'auth',
db: 0,
})
// listen method return Listener instance
redisPS.listen('channel name', (err, payload, listener) => {
// err - error or null
// payload - message payload
// listener - listener of this callback
if (err) {
// If the listener is no longer needed, you must manually call the listener.stop().
listener.stop();
console.error(err, listener);
}
console.log(payload);
});
// if you want to wait until message will receive, you can use 'once' method
(async () => {
// once return Promise with payload, so you can "await" they
const payload = await redisPS.once('channel name');
})();
redisPS.emit('channel name', { payload });
- Enable and use ESlint with Airbnb config
- Add tests with Ava
- Add possibility to set error timeout in 'once' listener
- Add option to allow only one callback in channel
- Optimize listening with pSubscribe
- Add Babel and use private fields in classes