3.0.0 • Published 7 years ago

@superbalist/js-pubsub-redis v3.0.0

Weekly downloads
10
License
MIT
Repository
github
Last release
7 years ago

@superbalist/js-pubsub-redis

A Redis adapter for the js-pubsub package.

Author Build Status Software License NPM Version NPM Downloads

Installation

npm install @superbalist/js-pubsub-redis

Usage

'use strict';

let redis = require('redis');
let RedisPubSubAdapter = require('@superbalist/js-pubsub-redis');

let client = redis.createClient({
  host: 'redis',
  port: 6379
});

let adapter = new RedisPubSubAdapter(client);

// consume messages
// note: this is a blocking call
adapter.subscribe('my_channel', (message) => {
  console.log(message);
  console.log(typeof message);
});

// publish messages
adapter.publish('my_channel', {first_name: 'Matthew'});
adapter.publish('my_channel', 'Hello World');

// publish multiple messages
let messages = [
  'message 1',
  'message 2',
];
adapter.publishBatch('my_channel', messages);

Examples

The library comes with examples for the adapter and a Dockerfile for running the example scripts.

Run make up.

You will start at a bash prompt in the /usr/src/app directory.

If you need another shell to publish a message to a blocking consumer, you can run docker-compose run js-pubsub-redis /bin/bash

To run the examples:

$ node examples/RedisConsumerExample.js
$ node examples/RedisPublishExample.js (in a separate shell)
3.0.0

7 years ago

2.0.0

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.0.1

7 years ago