Skip to content
This repository was archived by the owner on Sep 17, 2019. It is now read-only.
Christian Drengenberg edited this page Oct 18, 2017 · 4 revisions

RedisEvents

Kind: global class

new RedisEvents(config)

Class providing publishing and subscribing Redis events.

Param Type Description
config object For a list of possible configuration values see DefaultConfig.

redisEvents.subscribe(channel, callback) ⇒ Promise

This methods allows you to subscribe to one or more event channels. A channel can either be a full name of a channel or a Redis subscribe-pattern. A channel or pattern can only be subscribed once.

Depending on whenever a full channel name or a channel pattern is passed, the callback registered for the channel gets called with a different set of input parameters. Full channels get called with two parameters (message, channel), patterns get called with three parameters (message, channel, pattern).

Kind: instance method of RedisEvents
Returns: Promise - Promise resolving with true if the subscription succeeded. Otherwise false or an error.

Param Type Description
channel string Full name of a channel or a Redis subscribe-pattern.
callback function Function to be called when a message for a channel arrives.

redisEvents.unsubscribe(channel) ⇒ Promise

This method allows you to unsubscribe from a previous subscribed channel or pattern.

Kind: instance method of RedisEvents
Returns: Promise - Promise resolving with true or false.

Param Type Description
channel string Full name of a channel or a Redis subscribe-pattern.

redisEvents.disposeSubscriber() ⇒ Promise

Method for releasing all subscriptions and closing the connection to the Redis server.

Kind: instance method of RedisEvents
Returns: Promise - Promise resolving with true or false if there was no active connection.

redisEvents.emit(message, channel) ⇒ Promise

Method raising an event on the passed channel. The message sent can be any serializable object. If the instance of RedisEvents was constructed with a context or extended using the contextify() method and the message parameter contains an object, the message gets extended with this context before the event is raised.

You might want to leave the channel parameter empty if the instance of RedisEvents was constructed passing the defaultEmitChannel parameter found at DefaultConfig.

Kind: instance method of RedisEvents
Returns: Promise - Promise resolving with true when the event was published or rejecting with an error.

Param Type Description
message object JSON compatible JavaScript object.
channel string Full name of the channe the event should be published at.

redisEvents.disposeEmitter() ⇒ Promise

Method for closing the publishing connection to the Redis server.

Kind: instance method of RedisEvents
Returns: Promise - Promise resolving with true or false if there was no active connection.

redisEvents.disposeAll() ⇒ Promise

Releases all subscriptions, publishing channels and Redis connections.

Kind: instance method of RedisEvents
Returns: Promise - Promise resolving with two results.

redisEvents.contextify()

Allows adding a default context to every event emitted if the message passed to the emit() method already is an object. You may also want to construct an instance of RedisEvents by passing the context parameter to the constructor. For further information have a look at DefaultConfig.

Kind: instance method of RedisEvents

redisEvents.hasSubscription() ⇒ boolean

Checks whenever the passed channel or pattern already has an active subscription from the current instance of RedisEvents. The channel can either be a full name of a channel or a Redis subscribe-pattern.

Kind: instance method of RedisEvents
Returns: boolean - Returns true if the channel is already registered; otherwise false.

RedisEvents.DefaultConfig

Static object representing a default configuration set.

Kind: static property of RedisEvents
Properties

Name Type Description
serializer object Function to use for serializing messages in order to send them.
parser object Function to use for deserializing messages received.
defaultEmitChannel object Full name of a channel to emit events to if the channel is not passed to the emit() method.
consul object Object for configuring consul related parameters.
consul.host object Hostname of a consul server.
consul.redisServiceName object Name of the enpoint for the Redis server in consul.
consul.redisPasswordKey object Consul configuration key for Redis authorisation. Might be null or false if not desired to be used.
context object Optional context object to automatically extend emitted messages.