2.3.17 • Published 4 years ago

primus-rooms-redis-adapter v2.3.17

Weekly downloads
47
License
MIT
Repository
github
Last release
4 years ago

primus-rooms-redis-adapter

Build Status NPM version dependencies Status

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 = require('primus');
var Redis = require('ioredis');
var Adapter = require('primus-rooms-redis-adapter');

var redis = new Redis(/* options */);
var adapter = new Adapter(redis, {/* options */});

Once the adapter has been initialized it can be used to initialize the primus-rooms plugin.

// as an argument 
var primus = new Primus(http, {
  transformer: 'websockets',
  rooms: {adapter: adapter},
  plugin: {
    'rooms': require('primus-rooms'),
  },
});

// or by setting the property
primus.adapter = new Adapter();

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.config(options, function(){
  console.log('clean exit');
});
// or 
primus.adapter.config(options);

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:

NameTypeDescriptionDefault
namespaceStringnamespace to use in redis storagebumblebee
metroplexOmegaSupremeBooleanUse omega-supreme to broadcast to all servers through metroplexfalse

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.

NameTypeDescriptionDefault
metroplexOmegaSupremeBooleanUse omega-supreme to broadcast to all servers through metroplexinitilized value
primusObjectPrimus instance to be used to preform clean exitundefined
cbFunctionCallback function after a clean exit is preformedundefined
2.3.17

4 years ago

2.3.16

4 years ago

2.3.15

4 years ago

2.3.14

4 years ago

2.3.13

4 years ago

2.3.12

4 years ago

2.3.11

4 years ago

2.3.10

4 years ago

2.3.9

4 years ago

2.3.8

4 years ago

2.3.7

4 years ago

2.3.6

5 years ago

2.3.5

5 years ago

2.3.4

5 years ago

2.3.3

5 years ago

2.3.2

5 years ago

2.3.1

5 years ago

2.3.0

5 years ago

2.2.2

5 years ago

2.2.1

6 years ago

2.2.0

7 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.1.0-beta

7 years ago

2.0.0-beta

7 years ago

2.0.0

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago