primus-rooms-redis-adapter
Redis adapter for primus-rooms. Provides integration with metroplex and omega-supreme to allow for multiple servers support.
Installation
$ npm install primus-rooms-redis-adapter --save
Getting started
The adapter relies on ioredis for the redis connection, if an incorrect instance is provided the adapter will throw an error
'use strict'; var Primus = ;var Redis = ;var Adapter = ; var redis = /* options */;var adapter = redis /* options */;
Once the adapter has been initialized it can be used to initialize the primus-rooms
plugin.
// as an argument var primus = http transformer: 'websockets' rooms: adapter: adapter plugin: 'rooms': ; // or by setting the propertyprimusadapter = ;
Metroplex and Omega-Supreme Integration
If you are using metroplex
and omega-supreme
plugins, you can use the config function to allow the adapter to handle the broadcasting, removing and other things
related to the multiple servers setup.
Example Metroplex and Omega-Supreme configuration
var options = metroplexOmegaSupreme: true primus: primus; adapter;// or primusadapter;
API
new Adapter(redis, [options])
The constructor allows you to initialize the adapter. It requires an ioredis instance connected to a redis db.
The following (optional) options can be provided:
Name | Type | Description | Default |
---|---|---|---|
namespace | String | namespace to use in redis storage | bumblebee |
metroplexOmegaSupreme | Boolean | Use omega-supreme to broadcast to all servers through metroplex |
false |
adapter.config([options], [cb])
Function to configure the adapter, allows for setting flags as well as enabling clean exit logic on app termination. To add the listeners for cleanExit a primus instance must be passed in.
Note: Preforming cleanExit can take a while especially if the http server timeout is set too high.
The reason for that is due to node design, see issue #2642.
I recommend setting http server timeout to based on the server load higher load longer time to finish up
sending data to the user. To set the time out use require('http').createServer().setTimeout(x);
where x
is the timeout duration you want to allow a keep-alive request to be in idle before terminating it.
Name | Type | Description | Default |
---|---|---|---|
metroplexOmegaSupreme | Boolean | Use omega-supreme to broadcast to all servers through metroplex |
initilized value |
primus | Object | Primus instance to be used to preform clean exit | undefined |
cb | Function | Callback function after a clean exit is preformed | undefined |