Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@jcoreio/redis-subscriber

Package Overview
Dependencies
Maintainers
6
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jcoreio/redis-subscriber

subscribe specific callbacks to specific channels on the same redis client

latest
Source
npmnpm
Version
1.0.6
Version published
Maintainers
6
Created
Source

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

Keywords

redis

FAQs

Package last updated on 07 Oct 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts