RedChannel
Simplified pub/sub messaging with Redis
Warning
This library is intended for fast, fire-and-forget messaging, in situations where dropped messages are acceptable. This is due to the nature of Redis pub/sub. Additionally, if you intend to use this library at scale, please set the events parameter in the constructor to false. This will improve performance, but prevent the use of event-specific listeners.
Available Scripts
In the project directory, you can run:
npm test
Runs the library test suite, and reports the results of each test.
npm build
Builds the library for production to the lib
folder.
It correctly bundles the library in production mode and optimizes the build for the best performance.
npm lint
Lints the project files.
Usage
JavaScript (Subscriber)
const Redis = ;const RedSubscriber = ; const client = ;// Use "new RedSubscriber(client, false)" if you intend to use this library at scaleconst channel = client; { // Subscribe to all messages on "global:logs". await channel; // (Generic listener) Process all messages published on "global:logs". channel; // (Event specific listener) Process all messages published on "global:logs". channel; // Check if subscribed to a channel console; // true // Unsubscribe from all messages on "global:logs". await channel; // Check if subscribed to a channel console; // false // Print current subscriptions console; // [] // Subscribe to all messages on "global:logs". await channel; // Print current subscriptions console; // ['global:events'] // (Generic listener) Process all messages published on "global:events". channel; // Clean up subscriptions. After this point a new instance must be created await channel; // Remove all event listeners (your responsibility). channel;}
JavaScript (Publisher)
const Redis = ;const RedPublisher = ; const client = ;const channel = client; { // Publish message to all listeners on "global:logs"; await channel; // Publish message to all listeners on "global:events"; await channal;}
TypeScript (Subscriber)
;; ;// Use "new RedSubscriber(client, false)" if you intend to use this library at scale;
TypeScript (Publisher)
;; ;;
License
MIT