# primus-rooms-redis-adapter

> redis adapter for primus-rooms plugin. Supports omega-supreme and metroplex

Latest version **2.3.17** (published 2020-03-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install primus-rooms-redis-adapter
pnpm add primus-rooms-redis-adapter
yarn add primus-rooms-redis-adapter
bun add primus-rooms-redis-adapter
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.3.17 |
| Published | 2020-03-18 |
| First published | 2016-12-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 15.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Fadee Kannah |
| Maintainers | fadeenk |
| Keywords | primus, primus-rooms, primus-rooms-adapter, primus-rooms-redis-adapter, rooms, store, redis, adapter |

## Links

- npm: https://www.npmjs.com/package/primus-rooms-redis-adapter
- Repository: https://github.com/fadeenk/primus-rooms-redis-adapter
- Issues: https://github.com/fadeenk/primus-rooms-redis-adapter/issues
- npm.io page: https://npm.io/package/primus-rooms-redis-adapter

## Dependencies (3)

- [primus](https://npm.io/package/primus.md) *
- [ioredis](https://npm.io/package/ioredis.md) *
- [primus-rooms-adapter](https://npm.io/package/primus-rooms-adapter.md) 0.3.2

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 2.3.17 (latest) — 2020-03-18
- 2.1.0-beta (beta) — 2017-01-14
- 2.3.16 — 2020-03-12
- 2.3.15 — 2020-02-28
- 2.3.14 — 2020-02-17
- 2.3.13 — 2019-12-22
- 2.3.12 — 2019-12-14
- 2.3.11 — 2019-12-03
- 2.3.10 — 2019-11-27
- 2.3.9 — 2019-11-24
- 2.3.8 — 2019-11-13
- 2.3.7 — 2019-11-04
- 2.3.6 — 2019-10-21
- 2.3.5 — 2019-10-20
- 2.3.4 — 2019-10-03
- … 19 more at https://npm.io/package/primus-rooms-redis-adapter/versions

## README

# primus-rooms-redis-adapter

[![Build Status](https://img.shields.io/travis/fadeenk/primus-rooms-redis-adapter/master.svg)](https://travis-ci.org/fadeenk/primus-rooms-redis-adapter)
[![NPM version](https://img.shields.io/npm/v/primus-rooms-redis-adapter.svg)](https://www.npmjs.com/package/primus-rooms-redis-adapter)
[![dependencies Status](https://david-dm.org/fadeenk/primus-rooms-redis-adapter/status.svg)](https://david-dm.org/fadeenk/primus-rooms-redis-adapter)

Redis adapter for [primus-rooms](https://github.com/cayasso/primus-rooms). 
Provides integration with [metroplex](https://github.com/primus/metroplex) and [omega-supreme](https://github.com/primus/omega-supreme) to allow for multiple servers support.

## Installation

```
$ npm install primus-rooms-redis-adapter --save
```

## Getting started

The adapter relies on [ioredis](https://github.com/luin/ioredis) for the redis connection, if an incorrect instance is provided the adapter will throw an error

```javascript
'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. 
```javascript
// 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`](https://github.com/primus/metroplex) and [`omega-supreme`](https://github.com/primus/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

```javascript
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:

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](https://github.com/nodejs/node/issues/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`

---
_Source: https://npm.io/package/primus-rooms-redis-adapter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
