redisemitter

0.0.4 • Public • Published

RedisEmitter

Install and test

npm install --save redisemitter
npm test

Setup

const RedisEmitter = require('redisemitter')
 
const options = {
  host: 'localhost',
  port: 6379,
  index: ['type', 'action', 'name', 'id']
}
const events = new RedisEmitter(options)

options

  • host the host redis should connect to.
    • default: '127.0.0.1'
  • port the port redis should connect to.
    • default: 6379
  • query the default query all event strings will be generated from.
    • default: ['type', 'action', 'name', 'id']

Emitting events

emit only takes one argument and the event pattern will be built from the message. In this case event:emit:*:*

events.emit({
  type: 'event',
  action: 'emit'
})

Subscribing to events

Unlike EventEmitter you subscribe to objects instead of strings (a string will be generated from your query). In this case event:*:*:*

events.on({
  type: 'event'
})

subscriptions

  • on(query, callback) subscribe to all events matching the query
  • once(query, callback) subscribe to the first event matching the query
  • any(callback) subscribe to any event

Unsubscribing to events

All subscriptions return a disposer that can be called to dispose the event listener.

const dispose = events.on({
  type: 'test'
}, (message) => {
 
  console.log(message)
 
  if (message.action === 'quit') {
    dispose()
  }
})

Readme

Keywords

none

Package Sidebar

Install

npm i redisemitter

Weekly Downloads

2

Version

0.0.4

License

MIT

Last publish

Collaborators

  • johano