redis-ps

1.0.1 • Public • Published

codestyle PRs Welcome node MIT License npm npm

Travis Coverage Status dependencies Status devDependencies Status

Sponsor

NPM

RedisPS

Wrapper for easy communication between processes via Redis Pub/Sub.

Install

npm install redis-ps
yarn add redis-ps

Create instance

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 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

  • 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

Package Sidebar

Install

npm i redis-ps

Weekly Downloads

0

Version

1.0.1

License

MIT

Last publish

Collaborators

  • cheerlesscloud