@jcoreio/redis-subscriber

subscribe specific callbacks to specific channels on the same redis client

Stats

StarsIssuesVersionUpdatedCreatedSize
@jcoreio/redis-subscriber
001.0.64 years ago5 years agoMinified + gzip package size for @jcoreio/redis-subscriber in KB

Readme

redis-subscriber

Build Status Coverage Status semantic-release Commitizen friendly

Subscribe specific callbacks to specific channels on the same redis client

Usage

import redis from 'redis'
import RedisSubscriber from '@jcoreio/redis-subscriber'

const client = redis.createClient()
const subscriber = new RedisSubscriber(client)

Subscribing

subscriber.subscribe('foo', (channel, message) => ...)
subscriber.psubscribe('foo/*', (pattern, channel, message) => ...)

Unsubscribing

There are two ways to unsubscribe:

  • call unsubscribe or punsubscribe
    const onMessage = (channel, message) => ...
    const onPMessage = (pattern, channel, message) => ...
    subscriber.subscribe('foo', onMessage)
    subscriber.psubscribe('foo/*', onPMessage)
    ...
    subscriber.unsubscribe('foo', onMessage)
    subscriber.unsubscribe('foo/*', onPMessage)
    
  • call the function returned by subscribe or psubscribe
    const unsubscribe = subscriber.subscribe('foo', onMessage)
    unsubscribe()
    
    const unsubscribe = subscriber.psubscribe('foo/*', onPMessage)
    unsubscribe()
    

parseMessage option

Parse all messages as JSON before sending them to callbacks:

const subscriber = new RedisSubscriber(client, {parseMessage: JSON.parse})

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.