redis-ps
v1.0.1
Published
Wrapper for easy communication between processes via Redis Pub\Sub.
Maintainers
Readme
RedisPS
Wrapper for easy communication between processes via Redis Pub/Sub.
Install
npm install redis-psyarn add redis-psCreate instance
You can connect to socket:
new RedisPS('/tmp/redis.sock');By Redis DSN:
new RedisPS('redis://:[email protected]: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 messages
// 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);
});Once
// 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');
})();Emit messages
redisPS.emit('channel name', { payload });Roadmap
- [x] Enable and use ESlint with Airbnb config
- [x] 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

